0
votes

If I do this : CreateThreads, setsched_affinity to CPU 0, then will all the threads also have affinity to CPU 0 If instead I reverse the sequence of action i.e. set_schedaffinity first and then create threads , will the threads have affinity

I am creating threads using pthreads library. Thanks for any answers

1

1 Answers

3
votes

The sched_setaffinity() call is Linux-specific, so this answer applies there.

A call to sched_setaffinity() affects only a single thread. A thread created with pthread_create() inherits the CPU affinity mask of its parent.

This means that if you change the affinity of the current thread after creating other threads, their affinity will remain the default; but if you do it in the reverse order, they will inherit the altered affinity set.