@@ -748,14 +748,14 @@ class TaskManager
748
748
std::exception_ptr err_ptr_{ nullptr };
749
749
};
750
750
751
+ #if (defined __linux__)
751
752
// find out which cores are allowed for use by pthread
752
753
inline std::vector<size_t >
753
754
get_avail_cores ()
754
755
{
755
756
auto ncores = std::thread::hardware_concurrency ();
756
757
std::vector<size_t > avail_cores;
757
758
avail_cores.reserve (ncores);
758
- #if (defined __linux__)
759
759
cpu_set_t cpuset;
760
760
int rc = pthread_getaffinity_np (pthread_self (), sizeof (cpu_set_t ), &cpuset);
761
761
if (rc != 0 ) {
@@ -766,9 +766,9 @@ get_avail_cores()
766
766
avail_cores.push_back (id);
767
767
}
768
768
}
769
- #endif
770
769
return avail_cores;
771
770
}
771
+ #endif
772
772
773
773
inline size_t
774
774
num_cores_avail ()
@@ -829,6 +829,8 @@ class ThreadPool
829
829
if (!task_manager_.called_from_owner_thread ())
830
830
return ;
831
831
832
+ active_threads_ = threads;
833
+
832
834
if (threads <= workers_.size ()) {
833
835
task_manager_.resize (threads);
834
836
} else {
@@ -845,7 +847,6 @@ class ThreadPool
845
847
set_thread_affinity ();
846
848
#endif
847
849
}
848
- active_threads_ = threads;
849
850
}
850
851
851
852
// ! @brief retrieves the number of active worker threads in the thread pool.
@@ -970,7 +971,7 @@ class ThreadPool
970
971
{
971
972
cpu_set_t cpuset;
972
973
auto avail_cores = sched::get_avail_cores ();
973
- for (size_t id = 0 ; id < workers_. size () ; id++) {
974
+ for (size_t id = 0 ; id < active_threads_ ; id++) {
974
975
CPU_ZERO (&cpuset);
975
976
CPU_SET (avail_cores[id % avail_cores.size ()], &cpuset);
976
977
int rc = pthread_setaffinity_np (
0 commit comments