// This program demonstrates how to change the worker behavior
// upon the creation of an executor.
#include
// ----------------------------------------------------------------------------
// Affinity
// ----------------------------------------------------------------------------
#if defined(__linux__)
#include
#include
#elif defined(_WIN32)
#include
#elif defined(__APPLE__)
#include
#include
#endif
// affine the given thread to a specific core
bool affine(std::thread& thread, size_t core_id) {
#if defined(__linux__)
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(core_id, &cpuset);
pthread_t native_handle = thread.native_handle();
return pthread_setaffinity_np(native_handle, sizeof(cpu_set_t), &cpuset) == 0;
#elif defined(_WIN32)
return SetThreadAffinityMask(thread.native_handle(), 1ULL