Unit 'exec' Package
[Overview][Constants][Types][Procedures and functions][Variables][Index] [#os4units]

InitSemaphore

Initialize a signal semaphore

Declaration

Source position: exec.pas line 1818

procedure InitSemaphore(

  SigSem: PSignalSemaphore

);

Arguments

SigSem

  

A pointer to a signal semaphore structure (with all fields set to 0 before the call)

Description

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.

See also

ObtainSemaphore

  

Gain exclusive access to a semaphore

ObtainSemaphoreShared

  

Gain access to a semaphore in shared mode

AttemptSemaphore

  

Try to obtain a Semaphore without blocking

ReleaseSemaphore

  

Make signal semaphore available to others

Procure

  

Asynchron locking of a semaphore

Vacate

  

Release a bidMessage from Procure()


Documentation generated on: 2021-07-30