This example waits for a muxwait semaphore to clear. Assume that the handle of the semaphore has been placed into hmux already. ulTimeout is the number of milliseconds that the calling thread will wait for the muxwait semaphore to clear. If the specified muxwait semaphore is not cleared during this time interval, the request times out.
#define INCL_DOSSEMAPHORES /* Semaphore values */ #define INCL_WINMESSAGEMGR #include <os2.h> #include <stdio.h> #ifndef ERROR_TIMEOUT #define ERROR_TIMEOUT 640 #define ERROR_INTERRUPT 95 #endif HMUX hmux; /* Muxwait semaphore handle */ ULONG ulTimeout; /* Number of milliseconds to wait */ ULONG ulUser; /* User field for the semaphore that */ /* was posted or released (returned) */ ULONG rc; /* Return code */ ulTimeout = 60000; /* Wait for a maximum of 1 minute */ rc = WinWaitMuxWaitSem(hmux, ulTimeout, &ulUser); /* On successful return, the ulUser variable contains the user */ /* identifier of the semaphore that caused the wait to terminate. */ /* If the caller had to wait for all the semaphores within the */ /* muxwait semaphore to clear, then the value corresponds to the */ /* last semaphore within the muxwait semaphore to clear. */ /* If the caller had to wait for any semaphore with the muxwait */ /* semaphore to clear, then the value corresponds to that */ /* semaphore. */ if (rc == ERROR_TIMEOUT) { printf("WinWaitMuxWaitSem call timed out"); return; } if (rc == ERROR_INTERRUPT) { printf("WinWaitMuxWaitSem call was interrupted"); return; } if (rc != 0) { printf("WinWaitMuxWaitSem error: return code = %ld", rc); return; }