Named and Anonymous Semaphores

A semaphore can be either named or anonymous. A named semaphore is always shared; that is, it is always available to any process that knows the name. An anonymous semaphore can be either private to a process or shared among processes, depending on whether the application includes the DC_SEM_SHARED flag in the function that creates the semaphore. A semaphore intended for use solely among threads of the same process can be anonymous and private.

OS/2 creates a named semaphore when an application specifies a name in the function that creates the semaphore. The name must have the following form:

    \SEM32\SemName

The "\SEM32\" is required, though it need not be uppercase. The semaphore name must conform to the rules for OS/2 file names, although no actual file is created for the semaphore. If the application does not specify a name in the function that creates the semaphore, OS/2 creates an anonymous semaphore.

OS/2 permits a system-wide maximum of 65536 (64K) shared semaphores. In addition, each process can use up to 65536 (64K) private semaphores.

A shared muxwait semaphore must contain either all shared event semaphores or all shared mutex semaphores. However, a private muxwait semaphore can contain a combination of shared and private event or mutex semaphores. OS/2 generates a unique handle when it creates a semaphore. Processes must obtain this handle before they can access the semaphore. A semaphore's handle is always available to the process that created the semaphore. A process can obtain the handle of a named semaphore created in another process by using the appropriate semaphore-opening function. A process that requires access to an anonymous shared semaphore that was created in another process must obtain the handle of the semaphore through some other form of interprocess communication, such as a pipe or a queue.


[Back: Multiple Wait (Muxwait) Semaphores]
[Next: Semaphore Management]