dos12.hlp (Table of Contents; Topic list)
DosOpenSem (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSSEMAPHORES
 
USHORT DosOpenSem(phsem, pszSemName)
PHSEM phsem;       /* pointer to variable for semaphore handle */
PSZ pszSemName;    /* pointer to semaphore name                */
 
The DosOpenSem function opens a system semaphore of the specified name and
returns a unique semaphore handle. The semaphore handle can then be used to
set and clear the semaphore and to carry out other tasks that use the
semaphore.
 
Parameter   Description
────────────────────────────────────────────────────────────────────────────
 
phsem       Points to the variable that receives the new semaphore handle.
 
pszSemName  Points to the null-terminated string that identifies the
            semaphore. The string must have the following form:
 
            \sem\name
 
            The string name, name, must have the same format as an MS OS/2
            filename and must identify a semaphore that has been created
            previously by using the DosCreateSem function.
 
Return Value
 
The return value is zero if the function is successful. Otherwise, it is an
error value, which may be one of the following:
 
     ERROR_INVALID_NAME
     ERROR_SEM_NOT_FOUND
     ERROR_TOO_MANY_SEMAPHORES
 
Comments
 
The DosOpenSem function only returns the handle of the semaphore; it does
not test or change the value of the semaphore. The semaphore handle is the
same as the semaphore handle returned by the DosCreateSem function that
created the semaphore.
 
If a process creates a child process by using the DosExecPgm function, the
new process inherits any open semaphore handles.
 
Under MS OS/2, system semaphores reside in a memory buffer rather than a
disk file. When the last process with an open semaphore terminates, that
semaphore is closed and is no longer available to any other process.
 
Example
 
This example calls the DosOpenSem function to open a system semaphore that
had been created previously:
 
HSEM hsem;                               /* handle to semaphore  */
DosOpenSem(&hsem, "\\sem\\abc.ext");     /* opens the semaphore  */
    .
    .
    .
DosCloseSem(hsem);                       /* closes the semaphore */
 
See Also
 
DosCloseSem, DosCreateSem, DosExecPgm, DosSemClear, DosSemRequest