Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Novlib 3.30 Online Reference - <b> semaphore functions overview</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 Semaphore functions overview
------------------------------------------------------------------------------
 Semaphores, like logical records or global system variables, are labels
 that indirectly control network activity. A semaphore is an ASCIIZ string
 with an associated value. A semaphore name can be up to 127 bytes in
 length. Its value may be from -127 through to 127.
 It is up to your program to define the influence of the semaphores it
 creates. Generally, semaphores are used to control access to a network
 resource. For example, a semaphore can be used to limit a resource to one
 user at a time, or to a specified maximum number of users.
 A program can access a semaphore resource by opening the associated
 semaphore using SemOpen(). If the semaphore does not exist, SemOpen() will
 create it. SemOpen() takes as parameters a semaphore name and an initial
 value. The initial value is assigned to the semaphore only if the semaphore
 does not already exist. SemOpen() returns a semaphore handle.

 A program can wait for a semaphore to become available using
 SemValueDecrement(), which decrements the value of a semaphore by one. If
 the resultant value is greater than or equal to 0, the program can access
 the semaphore's resource. If the value is a negative number, the program
 can be placed in a queue.
 Through the wTimeOut parameter, SemValueDecrement() passes the amount of
 time the program wants to wait for the semaphore. If the value becomes
 positive before the timeout expires, the program can access the resource.
 If the value is still negative when the timeout expires, the program is
 removed from the queue and the semaphore value is incremented.
 When a program finishes using a semaphore's resource, it must call
 SemValueIncrement() to increment the value of the semaphore. The program
 must also call SemClose() to decrement the open count of the semaphore by
 one. When a semaphore's open count reaches 0, the semaphore is deleted.
 Both of these calls require the semaphore handle as a parameter.

 The SemValueGet() function allows a program to query the value of a
 semaphore without attempting to open the semaphore. The semaphore value can
 be positive or negative (from -127 through 127). A positive value indicates
 that the program can open the semaphore and access its resource. A negative
 value indicates the number of processes waiting to open the semaphore.
 Based on this value, the program may have to wait until another program
 increments the semaphore before it can access the resource. A value of 0
 means the semaphore is effectively exclusive to the workstation performing
 the open. This technique may be used to implement semaphore locking.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson