Initialize a signal semaphore
Source position: exec.pas line 1304
procedure InitSemaphore( |
SigSem: PSignalSemaphore |
); |
SigSem |
|
A pointer to a signal semaphore structure (with all fields set to 0 before the call) |
This function initializes a signal semaphore and prepares it for use. It does not allocate anything, but does initialize list pointers and the semaphore counters.
Semaphores are often used to protect critical data structures or hardware that can only be accessed by one task at a time. After initialization, the address of the SignalSemaphore may be made available to any number of tasks. Typically a task will try to ObtainSemaphore(), passing this address in. If no other task owns the semaphore, then the call will lock and return quickly. If more tasks try to ObtainSemaphore(), they will be put to sleep. When the owner of the semaphore releases it, the next waiter in turn will be woken up.
Semaphores are often preferable to the old-style Forbid()/Permit() type arbitration. With Forbid()/Permit()>all other tasks are prevented from running. With semaphores, only those tasks that need access to whatever the semaphore protects are subject to waiting.
|
Gain exclusive access to a semaphore |
|
|
Gain access to a semaphore in shared mode |
|
|
Try to obtain a Semaphore without blocking |
|
|
Make signal semaphore available to others |
|
|
Asynchron locking of a semaphore |
|
|
Release a bidMessage from Procure() |