Creates or opens a semaphore.
HANDLE RtCreateSemaphore( LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName );
lpSemaphoreAttributes
lInitialCount
lMaximumCount
. A semaphore's state is signaled when its count is greater than zero, and nonsignaled when zero. The count decreases by one whenever a wait function releases a thread that was waiting for the semaphore. To increase the count by a specified amount, call RtReleaseSemaphore.
lMaximumCount
lpName
lInitialCount
and lMaximumCount
parameters because they were already set by the creation process.
You can use the handle returned by CreateSemaphore in any function that requires a handle to a semaphore object.
The state of a semaphore object is signaled when its count is greater than zero, and nonsignaled when its count is equal to zero. The lInitialCount parameter specifies the initial count. Each time a waiting thread is released because of the semaphore's signaled state, the semaphore count decreases by one. To increment a semaphore's count by a specified amount, use ReleaseSemphore. The count can never be less than zero or greater than the value specified in the lMaximumCount parameter.
Multiple processes can have handles of the same semaphore object, enabling use of the object for interprocess synchronization. To share an object, a process can specify the name of a semaphore object in a call to CreateSemaphore.
To close the handle, use RtCloseHandle. When the process terminates, the system automatically closes the handle. When its last handle closes, the semaphore object is destroyed.
RtCreateSemaphore can also be used within the real-time portion of your application to create an iwin32 semaphore.
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/nt/include/iwin32x.h | iwin32x.h | iwin32x.lib |
Notes
RtCloseHandle, RtReleaseSemaphore, iwin32x API, iwin32 Overview