Discrete Dipole Approximation Project  1.0
Plugin based Discrete Dipole Approximation (DDA) software package.
Thread::Semaphore Class Reference

Detailed Description

A Semaphore provides a more advanced synchronization then a Mutex like a Mutex, a Semaphore can be aquired and released by a thread however unlike a Mutex, a Semaphore may be aquired by several threads the number of threads that can hold a Semaphore is detrimed by its internal counter. This counter is declarmented when aquired and inclimented when released. The Semaphore may be aquired by a thread as long as the counter is more than 0.

#include "thread.h"

Public Member Functions

 Semaphore (unsigned int value)
 Constructs a new Semaphore object and sets the internal counter to value this indicates the maximum number of threads that can aquire the Semaphore a once. More...
 ~Semaphore ()
 Destroys the Semaphore object.
bool Post (unsigned int count=1)
 Release the Semaphore. More...
bool TryWait ()
 Atempts to aquire the Semaphore and returns immediately. More...
bool Wait (unsigned long timeout, bool execpt=true)
 Aquires the Semaphore object when the internal counter is more than 0. More...

Constructor & Destructor Documentation

Thread::Semaphore::Semaphore ( unsigned int  value)
[in]valueNumber of thread that can aquire at once

Member Function Documentation

bool Thread::Semaphore::Post ( unsigned int  count = 1)

This will result in the internal counter being increassed by count.

true on success, false on error.
[in]countNumber of times to release.
bool Thread::Semaphore::TryWait ( )

This function will fail if the Semaphore isn't free.

true if aquired, false otherwise.
bool Thread::Semaphore::Wait ( unsigned long  timeout,
bool  execpt = true 

If the Semaphore isn't free, this call will block until the Semaphore is free of timeout has been exceeded.

true if aquired, false otherwise.
TimeoutExceptionRaised in execpt is true and timeout has been exceeded.