13.18. NETWARE

About
Functions order

13.18.1. About NETWARE

13.18.2. NETWARE functions order

13.18.2.4. Function FT_NWSEMLOCK()

 FT_NWSEMLOCK ( <cSemaphore>, <@nHandle> ) -> lRet

13.18.2.5. Function FT_NWSEMOPEN()

 FT_NWSEMOPEN( <cName>, <nInitVal>, <@nHandle>, <@nOpenCnt> ) -> nRc

13.18.2.5.3. Description

A semaphore is simply a label that indirectly controls network activity. There is a semaphore name, which can be up to 127 characters, and an associated value, which can range from 0 to 127.

A semaphore can be used for many things, but is most often used to limit the number of users in an application, and to control access to a network resource.

A semaphore essentially allows you to place locks on resources other than files.

An application begins the process by calling FT_NWSEMOPEN(). If the semaphore doesn't exist, NetWare will create it. FT_NWSEMOPEN() returns a handle that is used in other semaphore calls.

Applications use FT_NWSEMWAIT() to wait for a semaphore to become available. FT_NWSEMWAIT() decrements the semaphore's value by 1. If the value > 0, then the application should be allowed to access the semaphore's resource. If the value goes negative, then the application is placed in a queue. How long your app is in the queue is determined by how you set the timeout parameter. If you can't get the resource in the time you allot, you're let out of the queue and the value increments by 1 again.

When an application finishes with a semaphore, it should call FT_NWSEMSIG() to increment the value, and then FT_NWSEMCLOSE() to close the semaphore. When the semaphore's open count goes to 0, NetWare deletes it.

FT_NWSEMEX() can be used to examine the value and open count without affecting them.

For an interesting discussion on the operating system aspects of semaphores, check "Operating Systems Design and Implementation" by A. Tanenbaum, page 60. For more details on NetWare's semaphore facilities, refer to Charles Rose's "Programmer's Guide to NetWare". The "Programmer's Guide" will make an excellent companion guide to the source code for all NetWare functions in the Nanforum Toolkit.