This example requests ownership of a mutex semaphore. Assume that the handle of the semaphore has been placed into hmtx already.
ulTimeout is the number of milliseconds that the calling thread will wait for ownership of the mutex semaphore. If the specified mutex semaphore is not released during this time interval, the calling thread does not receive ownership of it.
#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 HMTX hmtx; /* Mutex semaphore handle */ ULONG ulTimeout; /* Number of milliseconds to wait */ ULONG rc; /* Return code */ ulTimeout = 60000; /* Wait for a maximum of 1 minute */ rc = WinRequestMutexSem(hmtx, ulTimeout); if (rc == ERROR_TIMEOUT) { printf("WinRequestMutexSem call timed out"); return; } if (rc == ERROR_INTERRUPT) { printf("WinRequestMutexSem call was interrupted"); return; } if (rc != 0) { printf("WinRequestMutexSem error: return code = %ld", rc); return; }