In Windows on a multiprocessor machine, does a thread change the CPU/core during its lifetime?
Yes, threads and processes can run concurrently on multi-core CPUs, so this works as you describe (regardless of how you create those threads and processes, OpenMP or otherwise). A single process or thread only runs on a single core at a time.
Can two threads be assigned to different processors and execute at the same time? Yes. A couple of threads may be sharing a processor core, with one running while the other waits. Modern CPUs often have hyper-threading technology to make this switching back and forth quite cheap (little overhead, fast performance).
KEY DIFFERENCECores is an actual hardware component whereas thread is a virtual component that manages the tasks. Cores use content switching while threads use multiple CPUs for operating numerous processes. Cores require only a signal process unit whereas threads require multiple processing units.
A single CPU core can have up-to 2 threads per core. For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads.
Yes, by default a thread can be scheduled on any available core. You can set the thread affinity if you want to restrict a thread to a specific core or cores.
does a thread change the CPU/core during its lifetime?
It can. It doesn't necessarily change, but there is nothing preventing the operating system from moving a thread between cores.
The Windows API does provide some control over this via SetThreadIdealProcessor or SetThreadAffinityMask and SetProcessAffinityMask, if you need to control a thread's operation.
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