Re: Is there a way to get the current semaphore count?
- From: "jeffareid" <jeffareid@xxxxxxxxxxx>
- Date: Thu, 2 Jul 2009 14:03:52 -0700
Again not the point. ReleaseSemaphore already returns the "previous count"
as an optional output parameter, so why make a release count of zero call
illegal instead of allowing it to return the current count?
There is a workaround for the dequeing thread(s) as used in my example:
http://jeffareid.net/misc/mtcopy.zip
since the thread has ownership of the list via the mutex in the
WaitForMultipleObjects() call used to wait for ownership and presence of
a message in a single call, that thread can issue a ReleaseSemaphore()
with a count of 1 followed by a WaitForObject() for that semaphore
to restore it's count.
The same workaround would probably work for the enqueing thread, but
I don't like the idea of potentially signalling and then designalling
the semaphore, even though the mutex used for ownership prevents
the dequeuing thread that uses WaitForMultipleObjects() on both the
semaphore and mutex from waking up.
In either case, it's wasted overhead, especially in the signal
and designal case, simply because a release count of zero is
considered illegal, even though it has a valid purpose, to get
the "previous" count via the optional parameter.
.
- References:
- Is there a way to get the current semaphore count?
- From: jeffareid
- Re: Is there a way to get the current semaphore count?
- From: Carl Daniel [VC++ MVP]
- Re: Is there a way to get the current semaphore count?
- From: jeffareid
- Re: Is there a way to get the current semaphore count?
- From: Ben Voigt [C++ MVP]
- Re: Is there a way to get the current semaphore count?
- From: jeffareid
- Is there a way to get the current semaphore count?
- Prev by Date: Re: Is there a way to get the current semaphore count?
- Next by Date: _cgets() problem with Visual Studio
- Previous by thread: Re: Is there a way to get the current semaphore count?
- Next by thread: Re: Is there a way to get the current semaphore count?
- Index(es):
Relevant Pages
|