Class: TSemaphore

Declaration: CountingSemaphore.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

None.

Inherited By:

TLocalSemaphore TRecoverableSemaphoreHandle

Purpose:

WARNING: Do not directly #include CountingSemaphore.h in any of your files. It is included in this version of the CommonPoint application system for internal implementation. It will be removed in future versions (and the public classes it contains will be moved to other public headers). TSemaphore is an abstract class which defines the protocol for semaphores. It is derived by TLocalSemaphore and TRecoverableSemaphore.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

Derived classes TLocalSemaphore and TRecoverableSemaphore provide real implementation for clients.

Concurrency:

Multithread safe.

Resource Use:

No special requirements.

Member Function: TSemaphore::TSemaphore

TSemaphore ()

Interface Category:

API.

Purpose:

Default constructor.

Calling Context:

Called by the stream-in operators and derived class constructors.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

After construction the semaphore is in free state. This constructor is invoked only from the derived class constructors.

Member Function: TSemaphore::~TSemaphore

virtual ~ TSemaphore ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TSemaphore::Acquire

  1. virtual void Acquire ()
  2. virtual void Acquire (const TTime & maximumTime)

Interface Category:

API.

Purpose:

  1. Acquires the semaphore in restricted mode, without a timeout.
  2. Acquires the semaphore in restricted mode, with a timeout.

Calling Context:

  1. Called when the client desires read/write access to the resource protected by the semaphore.
  2. Called when the client desires read/write access to the resource protected by the semaphore.

Parameters:

Return Value:

None.

Exceptions:

Throws TSemaphoreException(TTimeOutException::kTimeExpired) if specified time expires.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TSemaphore::AcquireShared

  1. virtual void AcquireShared ()
  2. virtual void AcquireShared (const TTime & maximumTime)

Interface Category:

API.

Purpose:

  1. Acquires the semaphore in shared mode, without a timeout.
  2. Acquires the semaphore in shared mode, with a timeout.

Calling Context:

  1. Called when the client desires read-only access to the resource protected by the semaphore.
  2. Called when the client desires read-only access to the resource protected by the semaphore.

Parameters:

Return Value:

None.

Exceptions:

Throws TSemaphoreException(TTimeOutException::kTimeExpired) if specified time expires.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TSemaphore::Release

virtual void Release ()

Interface Category:

API.

Purpose:

Releases the semaphore.

Calling Context:

Called to relinquish the semaphore lock held by the client.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

Wakes up any waiting threads in FIFO order, also alternates between readers and writers.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.