- this->workers[i] = xbt_os_thread_create(nullptr, worker_main, data, nullptr);
- xbt_os_thread_bind(this->workers[i], core_bind);
- if (core_bind != std::thread::hardware_concurrency() - 1)
- core_bind++;
- else
- core_bind = 0;
+ this->workers[i] = new std::thread(worker_main, data);
+
+ /* Bind the worker to a core if possible */
+#if HAVE_PTHREAD_SETAFFINITY
+#if HAVE_PTHREAD_NP_H /* FreeBSD ? */
+ cpuset_t cpuset;
+ size_t size = sizeof(cpuset_t);
+#else /* Linux ? */
+ cpu_set_t cpuset;
+ size_t size = sizeof(cpu_set_t);
+#endif
+ pthread_t pthread = this->workers[i]->native_handle();
+ int core_bind = (i - 1) % std::thread::hardware_concurrency();
+ CPU_ZERO(&cpuset);
+ CPU_SET(core_bind, &cpuset);
+ pthread_setaffinity_np(pthread, size, &cpuset);
+#endif