Is a thread, once it is started, always running on the same CPU until it terminates? Or is it OS/Implementation dependent?
I’m asking this out of curiousity.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general, on a multi-core box, no. If the same core can be used, there may be an advantage to be gained by making use of data still in the L1 cache, as posted by others, but the downside of expicitly forcing core affinity is bad:
Thread X is created and bound to core 0.
Thread X runs.
Thread X blocks on a system call, for I/O or inter-thread comms maybe.
The OS runs thread Y on core 0.
Thread X becomes ready while cores 1, 2 and 3 are idle.
Now what?
Preempt thread Y unnecessarily? Overhead of moving Y, plus what if Y is also bound to core 0?
Block X again until Y blocks? Prevents X making progress when it could do.