circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 
Test Your EQ #147— Answer

Answer 6
Each process has to keep track of its own threads. It has to allocate stack space for each one. It has to have a program counter and stack pointer for each one. It also has to manage the registers associated with these values, filling in the appropriate values for the thread it wants to execute. Finally, it needs to have a timer (provided by the OS) to wake up the scheduler thread, and that thread does context switching among the other threads as appropriate.

Possible problems include:

  • Scheduling is not a trivial thing to program. Having user programs do this means that they could easily mess it up and fail to work at all. However, user-level thread software libraries are available to do this for you.
  • Because the OS doesn't know that the threads are running, one thread blocking on an I/O operation will appear to the OS that the whole process is blocked, and will remain blocked until the I/O completes. Even if other threads could run, they will not.
  • The kernel will schedule the processes based on their priorities. High-priority threads within a low-priority process will be scheduled with low priority relative to threads in other processes.
  • Overhead: all of the thread scheduling takes time. But the context switches are cheap.

Contributor: Naveen PN

Published: October-2002

   

E-mail eq@circuitcellar.com with questions or comments.

Back to Questions