Query the Value of a Semaphore
|
Have you ever wanted to take a look at the current value of a semaphore
whilst debugging your code, but don't want to alter the value of the semaphore
by ReleaseSemaphore?
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.
|
IT Offers
Partners
More for Developers
Top Authors
- Voted: 13 times.
- Voted: 11 times.
- Voted: 11 times.
- Voted: 10 times.
- Voted: 8 times.
- Paul Kimmel 214 articles
- Zafir Anjum 120 articles
- Tom Archer - MSFT 83 articles
- Mark Strawmyer 69 articles
- Bradley Jones 59 articles

