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

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




jeffareid wrote:
Apparently someone at Microsoft decided that a ReleaseSemaphore with
a count of zero is illegal, so it can't be used to get the count
value as a "previous" value. Is there a way to get the semaphore
count without affecting the signaling of the semaphore?

No.

And it's a good thing, too, because you could never rely on the
answer being correct (or even close), since another thread (or two,
or ten) could change it between when the function returns and when
your code examines the return value.

There could be many reasons for monitoring the count, but that wasn't
the point. ReleaseSemaphore returns the "previous count" as an
optional output parameter, so apparently someone at Microsoft thought
it was important enough to make the count accessable. So why make a
single exception to this and make a call with a release count of zero
illegal instead of just returning the "previous count"?

One of the reasons for monitoring the count is that sometimes the
behavior of an application can be altered if the count exceeds some
threshold. For example, if the count is being used as a pending message
counter
for a thread, then if the message count exceeds some threshold, the
message receiving thread could speeds up it's message processing by
altering it's behavior (a graphics thread reducing the quality and
increasing the speed of it's output).

Why would you use a semaphore to count messages? The Interlocked API would
be much better for anything like that.


.



Relevant Pages

  • Re: Is there a way to get the current semaphore count?
    ... and make a call with a release count of zero illegal instead of just ... of an application can be altered if the count exceeds some threshold. ... message receiving thread could speeds up it's message processing by ...
    (microsoft.public.vc.language)
  • Re: Questions (Space)
    ... and visualize something moving exactly that speed. ... With other things, I look at either more time, or more distance (or more ... driving speeds. ... Zero point sounds like a cool term for in a sci-fi ...
    (rec.arts.sf.composition)
  • Re: Questions (Space)
    ... so I can estimate speeds that are around typical driving ... or spacecraft traveling from one planet to another in the ... Zero point sounds like a cool term for in a sci-fi story. ... When you did math in school, did you do graphs with X and Y? ...
    (rec.arts.sf.composition)
  • Islam doesnt produce any geniuses
    ... Aether: Also called: Prana, Akasha, Chiaki, or Quantum Medium. ... and this was called ZPE zero point energy. ... if you travel at very high speeds your weight keeps ... Mass increases with speed and approaches infinity as velocity approaches ...
    (alt.religion.islam)
  • Re: P-38s vs Zeros
    ... What this really means is to not engage in a turning fight at slow speeds. ... the Zero could pull more g at slower speeds than Allied ...
    (rec.aviation.military)