Re: Is there a way to get the current semaphore count?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.








.



Relevant Pages

  • Re: Is there a way to get the current semaphore count?
    ... Is there a way to get the semaphore ... single exception to this and make a call with a release count of zero ... for a thread, then if the message count exceeds some threshold, the ... message receiving thread could speeds up it's message processing by ...
    (microsoft.public.vc.language)
  • Re: Is there a way to get the current semaphore count?
    ... Is there a way to get the semaphore ... so why make a release count of zero call ... A semaphore used to represent the count of messages in a fifo message ... queue, combined with a mutex for ownership of that queue during updates, ...
    (microsoft.public.vc.language)
  • Re: "Semaphore" - Was ist das?
    ... The semaphore cannot be set again. ... A semaphore object is a synchronization object that maintains a count ... between zero and a specified maximum value. ... The application specifies the semaphore object ...
    (microsoft.public.de.excel)
  • Re: Recursive mutex
    ... Use two additional fields for each recursive mutex: ... If the thread id is not equal request the semaphore. ... field and set the usage counter to 1. ... If the counter reaches zero, invalidate the thread id field and ...
    (comp.programming.threads)
  • Re: threads and semaphores in linux
    ... > I am writing a very simple multithreaded program in Linux Red Hat 8.0 ... > I am using semaphores to synchronize the threads. ... You are setting the initial value of the semaphore ) ... 'counter' then the initial value of the semaphore should be zero. ...
    (comp.os.linux.development.system)