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.2
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:
Lockable NonCopyable

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 ()
 
- Public Member Functions inherited from Lockable
virtual ~Lockable ()
 Destroy a Lockable object.
 
virtual void acquire ()=0
 
virtual bool tryAcquire (unsigned long timeout)=0
 
virtual void release ()=0
 

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()

CountingSemaphore ( int  initialCount = 0)

Create a new CountingSemaphore.

Parameters
count- initial count

Member Function Documentation

◆ acquire()

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_Exceptionthrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait.
See also
Lockable::acquire()

Implements Lockable.

◆ count()

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

◆ post()

void post ( )

Provided to reflect the traditional Semaphore semantics

See also
release()

◆ release()

virtual void release ( )
virtual

Increment the count, unblocking one thread if count is positive.

See also
Lockable::release()

Implements Lockable.

◆ tryAcquire()

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
timeoutmaximum amount of time (milliseconds) this method could block
Returns
  • true if the Semaphore was acquired before timeout milliseconds elapse.
  • false otherwise.
Exceptions
Interrupted_Exceptionthrown 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.

◆ tryWait()

bool tryWait ( unsigned long  timeout)

Provided to reflect the traditional Semaphore semantics

See also
tryAcquire(unsigned long timeout)

◆ wait()

void wait ( )

Provided to reflect the traditional Semaphore semantics

See also
acquire()

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