Semaphores

The least intrusive way to guarantee serial access to a shared resource is to associate a semaphore with it, and to acquire ownership of the semaphore before accessing the resource. The application threads will be suspended only when there is actual contention for the resource.

This does require all of the programmers involved to be careful to request the semaphore before accessing the resource, and to remember to free it when done. The classic solution to this is to build a low-level function which includes the serialization.

Semaphores are of three categories:

KSEMS will be discussed later, because we will focus first on items available to the application programmer. There are two basic kinds of 16-bit semaphores, and an add-on structure which makes a third type by aggregation.

They are the System Semaphore, the RamSem, and the FastSafe RamSem, which is an accounting structure prefixed onto a RamSem.

There are two types of 32-bit semaphores, Mutual Exclusion, or MutEx and Event Semaphores. It is also possible to wait on a list of EventSems or MutexSems, but all semaphores in a list must be of the same type.


[Back: DosSuspendThread & DosResumeThread]
[Next: 16-bit Semaphores]