// Example for setting thread affinity in Windows
#include
#include
DWORD WINAPI ThreadFunction(LPVOID lpParam) {
// Thread code here
return 0;
}
int main() {
HANDLE thread = CreateThread(NULL, 0, ThreadFunction, NULL, 0, NULL);
// Set thread affinity to CPU 0
DWORD_PTR processAffinityMask = 1;
SetThreadAffinityMask(thread, processAffinityMask);
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
return 0;
}
// Example for setting thread affinity in Linux
#include
#include
#include
void* ThreadFunction(void* arg) {
// Thread code here
return nullptr;
}
int main() {
pthread_t thread;
pthread_create(&thread, NULL, ThreadFunction, NULL);
// Set thread affinity to CPU 0
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset);
pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
pthread_join(thread, NULL);
return 0;
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?