Reducing the Count on a Semaphore Object

ID: Q94997

4.00    | 3.10 3.50 3.51 4.00
WINDOWS | WINDOWS NT kbprg

The information in this article applies to:

ReleaseSemaphore(), which increments the count of a given semaphore object by a specified amount, will not take a negative value.

If, for some reason, you want to reduce the number of available semaphore "slots" to temporarily restrict or reduce access, you may loop calling WaitForSingleObject() with a zero timeout, counting the number of times it succeeds. When you no longer need to hold the semaphore slots, call ReleaseSemaphore() with the number of slots counted.

Note that this method does not prevent other threads from taking a semaphore slot when your thread is looping.

Additional reference words: 3.10 3.50 3.51 4.00 95 KBCategory: kbprg KBSubcategory: BseMisc BseSync

Keywords          : kbnokeyword kbKernBase kbThread kbGrpKernBase 
Version           : 4.00    | 3.10 3.50 3.51 4.00
Platform          : NT WINDOWS

Last Reviewed: December 18, 1996