Decrementing a counting semaphore

Before accessing data protected by a counting semaphore, decrement the semaphore:

      // local counting semaphore
      localCountingSem->Decrement();
      // global counting semaphore
      globalCountingSemaphore->Decrement();
You can specify a maximum time to wait for the decrement operation to complete by passing an argument of type
TTime to Decrement(). If this period expires before the decrement operation completes, Decrement() throws a TTimeOutException with an error value of kTimeExpired.

Alternatively, you can use the TryDecrement() member function to attempt to decrement the semaphore without blocking. If the semaphore's count is greater than zero, TryDecrement() decrements the count and returns true. Otherwise, TryDecrement() immediately returns false.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker