Semaphores signal the beginning or ending of an operation and provide
mutually exclusive ownership of resources. Typically, semaphores are used
to prevent more than one process or thread within a process from accessing
a resource, such as shared memory, at the same time.
Semaphores are defined by OS/2 and reside in an internal memory buffer.
They are divided into three types, according to the functionality they provide:
- Event semaphores enable a thread to notify
waiting threads that an event has occurred. The waiting threads then resume
execution, performing operations that are dependent on the completion of
the signaled event.
- Mutual exclusion (mutex) semaphores enable
threads to serialize their access to shared resources. That is, ownership
of a mutex semaphore is used by cooperating threads as a prerequisite for
performing operations on a resource. (Threads cooperate by using the mutex
semaphore functions to ensure that access to the resource is mutually exclusive.)
- Multiple wait (muxwait) semaphores enable threads
to wait either for multiple events to occur, or for multiple resources to
become available. Alternatively, a flag can be set so that a thread waits
for any one of multiple events to occur, or for any one of multiple resources
to become available.
[Back]
[Next]