Previous | Next --- Slide 81 of 86
Back to Lecture Thumbnails
rchalla

How does the compiler know when/how to break the thread in the case of deadlock?

MansNotHot

The OS, not the compiler, handles thread scheduling. If a thread is waiting for a resource (ex. a lock) it will be put to sleep by the OS until the resource becomes available. In the case of deadlock, it will never wake.

kayvonf

Actually, in these examples the OS is not involved. We are talking about hardware multi-threading. So the hardware is making a decision on which thread to run on the processor each cycle. If a thread stalls (cannot make progress in the current cycle because of a dependency on an operation that has not yet completed (such as a memory fetch), then the processor will attempt to run instructions from another thread. From the OS's perspective both threads are running on the hardware concurrently.