Threads and CPU Affinity
Asked Answered
B

4

2

Lets say there are two processors on a machine. Thread A is running on P1 and Thread B is running on P2.

Thread A calls Sleep(10000);

Is it possible that when Thread A starts executing again, it runs on P2?

If yes, who decides this transition? If no, why not?

Does Processor store some data that which all threads it's running or OS binds each thread to Processor for its full lifetime ?

Belting answered 31/1, 2011 at 3:42 Comment(0)
U
1

It is possible. This would be determined by the operating system process scheduler and may also be dependent on the application that is running. No information about previously running threads is kept by the processor, aside from whatever is in the cache.

Ulla answered 31/1, 2011 at 3:49 Comment(0)
A
0

This is dependent on many things, it behaves differently depending on the particular operating system. See also: Processor Affinity and Scheduling Algorithms. Under Windows you can pin a particular process to a processor core via the task manager.

Autocrat answered 31/1, 2011 at 3:49 Comment(0)
C
0

Yes, it is possible. Though ultimately a thread inherits its CPU (or CPU core) from the process (executable.) In operating systems, which CPU or CPU core a process runs on for its current quanta (time slice) is decided by the Scheduler:

http://en.wikipedia.org/wiki/Scheduling_(computing)

-Oisin

Carolanncarole answered 31/1, 2011 at 3:50 Comment(0)
R
0

The OS decides which processor to run the thread on, and it may easily change during the lifetime of that thread, especially if there is a context switch (caused by the sleep). It's completely possible if the system is loaded that both threads will be running on the same processor (or core), just at different times. Or if there isn't any load on the system, both threads may continue to run on separate processors.

Razor answered 31/1, 2011 at 3:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.