Microsoft KB Archive/94997

{|
 * width="100%"|

INFO: Reducing the Count on a Semaphore Object

 * }

Q94997

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * the operating system: Microsoft Windows NT, versions 3.1, 3.5, 3.51, 4.0
 * Microsoft Windows 95
 * the operating system: Microsoft Windows 2000

-

SUMMARY
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 &quot;slots&quot; 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 query words: 3.10 3.50

Keywords : kbAPI kbKernBase kbOSWinNT310 kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin2000 kbThread kbThreadSync kbOSWin95 kbDSupport kbGrpDSKernBase

Issue type : kbinfo

Technology : kbAudDeveloper kbWin32sSearch kbWin32API