From EDM2
Jump to: navigation, search

DosQueryMutexSem returns the process ID, thread ID and request count of the owner of the mutex semaphore referred to by hmtxSemaphore.


DosQueryMutexSem( hmtxSemaphore, ppidSemaphoreOwner, ptidSemaphoreOwner, pulRequestCount )


HMTX hmtxSemaphore (input)
The handle (HMTX) of the semaphore to be queried.
PPID ppidSemaphoreOwner (output)
A pointer to the process ID structure (PID) that will get the ID of the semaphore owner.
PTID ptidSemaphoreOwner (output)
A pointer to the thread ID structure (TID) that will get the ID of the current semaphore owner.
PUL pulRequestCount (output)
A pointer to the ULONG that is to get the request count of the queried mutex semaphore. The request count is calculated by subtracting the number of releases from the number of requests made on the mutex semaphore. If the semaphore currently has no owner then the request count is zero (0).


The following values can be returned
0 NO_ERROR Semaphore queried successfully
6 ERROR_INVALID_HANDLE Error, The value in phmtxSemaphore does not point to a valid semaphore, The calling process must first have access to the semaphore in question
87 ERROR_INVALID_PARAMETER Error, One or more parameters is not recognized, See parameters above
105 ERROR_SEM_OWNER_DIED Error, The process that owns the semaphore has died before releasing it, The values returned in ppidSemaphoreOwner and ptidSemaphoreOwner refer to

this dead owner

Usage Explanation

The process calling DosQueryMutexSem must first obtain access to the semaphore in question or ERROR_INVALID_HANDLE will be returned.

Sample Code

#include <os2.h>

HMTX  hmtxMySemaphore;     /* pointer to my semaphore handle */
PID   pidSemaphoreOwner;   /* will get PID of sem owner */
TID   tidSempahoreOwner;   /* will get TID of sem owner */
ULONG ulRequestCount;      /* will get the request count for the sem */

	/* access is gained to the semaphore in question */
	/* either by DosCreateMutexSem ... */
	/* ... or by DosOpenMutexSem */
	/* its handle is placed in hmtxMySemaphore */

	rc = DosQueryMutexSem(hmtxMySemaphore,

	if (rc != 0)
	  /* We got an error to take care of. */

See Also