Query the Value of a Semaphore
Posted
by Hermann Schinagl
on March 6th, 1999
Well, Win32 does not give you the possibilty to get the value, but there is a call in ntdll.dll which allows to query the semaphore. So the 'QuerySemaphore.lib' simply provides a small static lib, which wraps the NtQuerySemaphore call in ntdll.dll.
QuerySemaphore.lib is selfcontained, so your program does not need ntdll.lib to resolve the call to NtQuerySemaphore.
A simple example
#include "QuerySemaphore.h" LONG Value, v1; // Create a semaphore HANDLE Handle = CreateSemaphore(NULL, 4, 10, NULL); // Query the content of a semaphore QuerySemaphore(Handle, &Value); // Acquire Semaphore WaitForSingleObject(Handle, INFINITE); // Query again QuerySemaphore(Handle, &Value);
So all you need is to include 'QuerySemaphore.h' in your sourcecode and add 'QuerySemaphore.lib' to the libraries you are linking against.

Comments
RE: What about W95/W98?
Posted by Legacy on 03/14/1999 12:00amOriginally posted by: Hermann Schinagl
> And also, does this function provide proper locking on multiprocessor
> systems ??
Yes it does, because it is a System call in Windows NT.
> What Abot Win95/98 ??? Is there any way to query semaphore value
> in 95/98 ?
Uhh, I don't know.. But I guess it it is very different, because
the architecture of W95/W98 is different to Windows NT.
Ciao Hermann
Reply