Download The Raven Kernel: a Microkernel for Shared Memory
Transcript
Chapter 4. User level kernel implementation 101 4.3.8 Sleeping a thread The thread sleeping facility is used to suspend the execution of threads for a predetermined length of time. The sleep facility is built on top of the task timer service, which generates upcall events at specied times. The timer handler() upcall routine and thread sleep() routine share a sorted queue, thread sleep q. Sleeping threads are placed on this queue, sorted in the order of wakeup time. When timer handler() is called, expired threads on the thread sleep q are placed on the ready queue and executed. int thread_sleep( unsigned long sleep_time ); puts the caller thread to sleep for the specied number of clock ticks. The number of clock ticks per second is a value that is interactively set at kernel boot time. thread sleep() 4.4 Semaphore management Semaphores provide a way to synchronize actions and communicate events between threads. A common use for semaphores is to provide mutual exclusion around a piece of sensitive code. Other uses include controlling producer/consumer type problems between threads. For example, the interprocess communication system uses semaphores to synchronize message passing events between threads. The user level semaphore library, sem.c and global sem.c, provides two types of semaphores through the same function call interface. Lightweight semaphores, local to an address space can be created for exclusive use between threads in the same address space (used by the local IPC implementation). Global semaphores can also be created, which allow threads in remote address spaces to synchronize between each other (used by the global IPC implementation). The global semaphore implementation requires special hooks into the kernel, and is therefore slightly more costly in terms of performance. A parameter in the sem create() call allows the caller to specify whether a local or global semaphore should be created.