CreateSemaphore Function

Action

Creates a named or unnamed semaphore object.

Include file

Kernel.bdh

Syntax

CreateSemaphore(in nSecurity : number,
in nInitCount : number,
in nMaxCount : number,
in sName : string): number;

Return value

handle to the semaphore object

Parameter Description
nSecurity Security attributes for the semaphore object. This parameter must always be set to NULL.
nInitCount

Initial count for the semaphore object. This value must be greater than or equal to zero and less than or equal to nMaxCount.

The initial count value is not set if the specified semaphore object already exists.

nMaxCount

Maximum count for the semaphore object. This value must be greater than zero.

The maximum count value is not set if the specified semaphore object already exists.

sName Name of the semaphore object.

Example

dcltrans
transaction TMain
constMAX_USERS := 25;
var
hSemaphore: number;
begin
hSemaphore := CreateSemaphore(NULL, MAX_USERS,
MAX_USERS, "semaphore");
...
WaitForSingleObject(hSemaphore, INFINITE);
// perform critical work
...
ReleaseSemaphore(hSemaphore, 1);
...
end TMain;