Acquiring a semaphore

To acquire a semaphore for reading only:

      // acquire a local semaphore for reading
      try {
          localSem->AcquireShared();
      }
      catch (const TSemaphoreException&) {
          // handle exception...
      }
    
      // acquire a recoverable semaphore for reading
      try {
          recoverableSem->AcquireShared();
      }
      catch (const TSemaphoreException&) {
          // handle exception...
      }
    
To acquire a semaphore for writing:

      // acquire a local semaphore for writing
      try {
          localSem->Acquire();
      }
      catch (const TSemaphoreException&) {
          // handle exception...
      }
    
      // acquire a recoverable semaphore for writing
      try {
          recoverableSem->Acquire();
      }
      catch (const TSemaphoreException&) {
          //handle exception...
      }
You can specify a maximum time to wait for the semaphore to become available by passing an argument of type TTime to either Acquire() or AcquireShared(). If this period expires before the semaphore becomes available, the acquire function throws a TTimeOutException with an error value of kTimeExpired.


[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