OpenSemaphore

Opens the specified semaphore or creates it if it does not exist

Local Servers:blocking
Remote Servers:blocking
Classification:3.x, 4.x, 5.x, 6.x
Service:Server-Based Synchronization

Syntax

  #include <\nlm\nit\nwsync.h>  
   
  int OpenSemaphore (  
     char   *semaphoreName,  
     int     initialValue,  
     long   *semaphoreHandle,  
     WORD   *openCount); 
  

Parameters

semaphoreName
(IN) Specifies the string containing the name of the semaphore. (_MAX_SEMAPHORE_VALUE, defined in NWSYNC.H, is 128 characters, including the NULL terminator).
initialValue
(IN) If semaphore does not yet exist, it is assigned this value (1 to 127).
semaphoreHandle
(OUT) Receives semaphore handle.
openCount
(OUT) Receives the number of processes that have the semaphore open.

Return Values

Decimal

Hex

Constant

0

(0x00)

ESUCCESS

254

(0xFE)

ERR_INVALID_SEMAPHORE_NAME_LENGTH

255

(0xFF)

ERR_INVALID_INITIAL_SEMAPHORE_VALUE

Remarks

For cross-platform functionality, call NWOpenSemaphore.

The semaphoreValue is ignored unless this call creates the semaphore (because it did not already exist). The value can range from 1 to 127, indicating that only 1 to 127 processes can access the network resource at a time. A call to SignalSemaphore increments this value. A call to WaitOnSemaphore decrements this value.

The openCount indicates the number of processes holding the semaphore open. A call to OpenSemaphore increments this value. A call to CloseSemaphore decrements this value.

The value returned in the semaphoreHandle parameter is the semaphore handle. The application must pass this value in calls to all other semaphore functions.

The application must pass either the name of an existing semaphore or the name of the new semaphore in the semaphoreName parameter. A semaphore name is an ASCIIZ string from 1 to 127 bytes long.

If the specified semaphore does not exist, this function creates and initializes the semaphore to initialValue.

The openCount parameter indicates the number of processes using the semaphore.

See Also

CloseSemaphore, ExamineSemaphore, SignalSemaphore, WaitOnSemaphore