Previous | Next --- Slide 54 of 79
Back to Lecture Thumbnails
skylake

Does OS allocate all the threads to a single core CPU and then the CPU hardware decides which thread to run ?

I am a bit confused here - Earlier Prof. told that the OS picks which CPU to run the thread on, in case of multi processor chip. But later, at around 1:16:00 he mentions that it is like the OS gives the threads to run to the single core CPU, which decides which thread to run to increase throughput by avoiding memory fetch stalls. (He does mention that the hardware takes that call to improve performance in case of stalls due to memory fetches and that it would be very costly if the OS did it, like in case of IO).

How does the CPU manage this - is it through some hardware emulation of a thread ? How does it know the list of threads it can choose from ?

grizt

@skylake: While I've never taken OS, it's my impression that when you (as a C programmer) try to create a thread, you do not know what processor it runs on. That's up to the operating system (in a process known as scheduling). I haven't reviewed that part of the recording, but it seems like it's entirely possible that after the OS tells the processor to handle a thread, the processor decides which threads to run, when, and in what order. I don't know how that works at the hardware level, though. Hopefully someone else can elaborate on that!