Possible Duplicate:
how to set CPU affinity of a particular pthread?
I am writing a c++ program, using g++ compiler in Ubuntu. I have 4 threads in my program and 4 cores on my CPU. I want to be sure that each thread will be run on a different core. I am rarely familiar with pthread.
See sched_setaffinity function: http://manpages.courier-mta.org/htmlman2/sched_setaffinity.2.html
Don't do this. Let the system schedule the threads. If you affinitise the threads to distinct cores you just handicap the scheduler. When your app is the only one consuming CPU, the scheduler will naturally schedule each thread on a separate core.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With