NetWare provides system request that enable you to create, open, examine, and close semaphores. You can also use semaphore system requests to increment and decrement the value associated with a semaphore.
Like a logical record lock, a semaphore is a name associated with network resources such as files and records. Both logical record locks and semaphores limit the number of clients that can access network resources at one time. Logical record locks limit the number of clients to one. Semaphores, however, allow a configurable number of clients (1 to 127) to access a network resource at one time.
When you create a semaphore using Open Semaphore 0x2222 32 0, you assign a value to the semaphore to indicate how many clients can simultaneously access the resource associated with the semaphore. For example, a semaphore value of 4 indicates that 5 (0 to 4) clients can access the associated resource at one time. All requests that access a semaphore must obtain a semaphore handle by first calling Open Semaphore.
After opening an existing semaphore, you must first check the semaphore's value by calling Examine Semaphore 0x2222 32 1. If the value is greater than or equal to zero, you can access the associated network resource. You then decrement the value by calling Wait On Semaphore 0x2222 32 2 so you can access the resource. After accessing the resource, you increment the semaphore value by calling Signal Semaphore 0x2222 32 3 and then exiting the semaphore.
If the semaphore value is negative, you cannot access the resource immediately. You can either wait a specified timeout interval for the resource to become available or you can retry later.
The following algorithm illustrates semaphore usage:
Open Semaphore
Examine Semaphore
If semaphore value < 0, go to step 6.
Wait On Semaphore
Access the associated resource
Signal Semaphore
Close Semaphore