Question

I apologize if this question is a bit out there, but it seems interesting to me and I cannot find any good answer from my research. I know that an operating system has a main system thread that does tasks such as manage other threads, but how exactly does this work on a single-core processor that is not hyperthreaded? In my thinking, it wouldn't be possible to give control to another thread that an application was using, as this would cause the system thread to block. But obviously it is possible, so how exactly does it work? I have thought of the system thread incorporating the work of the other threads into its own, but that just seem like it would be a horrible idea to me.

Was it helpful?

Solution

'I know that an operating system has a main system thread that does tasks such as manage other threads' - NO, not in preemptive, multithreaded OS, ie. all effective ones.

After boot time, the OS is only entered by threads upon an 'interrupt'. There are software interrupts - system calls, and hardware interrupts via drivers, that can change the state of threads. Between these interrupts, the OS does nothing at all. No interrupts: the OS does nothing.

I appreciate that this is difficult to grasp, especially with the mostly piss-poor 'Intro to Threads' pages/chapters, but that is how it is.

Be aware that a large pile of stuff re. threads on the web etc. is either inadequate, misleading, over-simplified or actually wrong. Common wrongness keyphrases: 'time-slice', 'quantum', 'round-robin', 'timer-scheduled'.

OTHER TIPS

I know that an operating system has a main system thread that does tasks such as manage other threads...

In every operating system I'm familiar with, the scheduler is run by all CPUs when task switching occurs. There is no "main system thread".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top