If you can read this text, it means you are not experiencing this website at its best. This website is designed for used with a standards-compliant browser.
Current version: 2.3.1
ZThreads
A platform-independent, multi-threading and synchronization library for C++
Home Documentation Downloads CVS Contact

# CountingSemaphore Class Reference

`#include <CountingSemaphore.h>`

Inheritance diagram for CountingSemaphore:

List of all members.

## Public Member Functions
| CountingSemaphore (int initialCount=0)
virtual | ~CountingSemaphore ()
| Destroy the CountingSemaphore.
void | wait ()
bool | tryWait (unsigned long timeout)
void | post ()
virtual int | count ()
virtual bool | tryAcquire (unsigned long timeout)
virtual void | acquire ()
virtual void | release ()

## Detailed Description

Author:
  Eric Crahen <http://www.code-foo.com>

Date:
  <2003-07-16T15:26:18-0400>

Version:
  2.2.1

A CountingSemaphore is an owner-less Lockable object.

It differs from a normal Semaphore in that there is no upper bound on the count and it will not throw an exception because a maximum value has been exceeded.

See also:
  Semaphore

Threads blocked on a CountingSemaphore are resumed in FIFO order.

## Constructor & Destructor Documentation

CountingSemaphore | ( | int | initialCount = 0 | ) |

  | Create a new CountingSemaphore. Parameters:
  count | - initial count

## Member Function Documentation

virtual void acquire | ( |  | ) | `[virtual]`

  | Decrement the count, blocking that calling thread if the count becomes 0 or less than 0. The calling thread will remain blocked until the count is raised above 0 or if an exception is thrown. Exceptions:
  Interrupted_Exception | thrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait.
See also: Lockable::acquire() Implements Lockable.

virtual int count | ( |  | ) | `[virtual]`

| Get the current count of the semaphore. This value may change immediately after this function returns to the calling thread. Returns: int count

void post | ( |  | ) |

| Provided to reflect the traditional Semaphore semantics See also: release()

virtual void release | ( |  | ) | `[virtual]`

| Increment the count, unblocking one thread if count is positive. See also: Lockable::release() Implements Lockable.

virtual bool tryAcquire | ( | unsigned long | timeout | ) | `[virtual]`

  | Decrement the count, blocking that calling thread if the count becomes 0 or less than 0. The calling thread will remain blocked until the count is raised above 0, an exception is thrown or the given amount of time expires. Parameters:
  timeout | maximum amount of time (milliseconds) this method could block
  Returns: true if the Semaphore was acquired before timeout milliseconds elapse. false otherwise. Exceptions:
  Interrupted_Exception | thrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait.
See also: Lockable::tryAcquire(unsigned long timeout) Implements Lockable.

bool tryWait | ( | unsigned long | timeout | ) |

| Provided to reflect the traditional Semaphore semantics See also: tryAcquire(unsigned long timeout)

void wait | ( |  | ) |

| Provided to reflect the traditional Semaphore semantics See also: acquire()

The documentation for this class was generated from the following file:

- CountingSemaphore.h