Posting an Event Semaphore

DosPostEventSem posts the semaphore, if it is not already posted, and increments the post count. All threads that have called DosWaitEventSem for this semaphore are unblocked and resume execution. Threads that call DosWaitEventSem after the event semaphore has been posted and before the next time it is reset, will return immediately from a call to DosWaitEventSem and continue execution. If the semaphore is subsequently reset, threads that call DosWaitEventSem will again be blocked.

Any thread in the process that created an event semaphore can post the semaphore by calling DosPostEventSem. Threads in other processes can also call DosPostEventSem, but they must first gain access to the semaphore by calling DosOpenEventSem.

The following code fragment posts a system event semaphore. Assume that the handle of the semaphore has been placed into HEV already.

    #define INCL_DOSSEMAPHORES   /* Semaphore values */
    #include <os2.h>
    #include <stdio.h>

    HEV     hev;     /* Event semaphore handle */
    APIRET  ulrc;    /* Return code            */

    ulrc = DosPostEventSem(hev);

    if (ulrc != 0) {
        printf("DosPostEventSem error: return code = %ld",
               ulrc);
        return;
    }

OS/2 maintains a post count for each event semaphore. The post count is the number of times the semaphore has been posted (with DosPostEventSem) since the last time the semaphore was in the reset state.

If the event semaphore is reset when DosPostEventSem is called, the semaphore is posted and the post count is set to 1. If the event semaphore is already posted when DosPostEventSem is called, the post count is incremented, and ERROR_ALREADY_POSTED is returned to the calling thread.

The post count is returned as output by DosResetEventSem; it can also be obtained by calling DosQueryEventSem.

The maximum number of times an event semaphore can be posted is 65535. The value of the post count cannot exceed 65535. If an attempt is made to exceed this number, DosPostEventSem returns ERROR_TOO_MANY_POSTS.


[Back: Resetting an Event Semaphore]
[Next: Waiting for an Event Semaphore]