[ previous ] [ next ] [ threads ]
 To :  "Yate mailing list" <yate@v...>
 From :  "Andrew McDonald" <andrew.mcdonald@n...>
 Subject :  RE: [yate] Condition class proposal
 Date :  Thu, 10 Aug 2006 14:55:32 +0800
Boost (http://www.boost.org) has a threading library
http://www.boost.org/doc/html/threads.html
which contains a condition variable class
http://www.boost.org/doc/html/condition.html

Using this it is relatively simple to write constructs such as monitored queues.

The Boost vault (http://www.boost-consulting.com/vault/) contains various other higher level concurrency constructs built on top of the threading library, such as futures, deferred processing and an implementation of the N1883 proposal for threading in TR2
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1883.pdf)

regards, 

Andrew McDonald
System Architect

Norwood Systems Australia Pty Ltd
71 Troy Terrace
PO Box 1281
Subiaco, WA 6904

Tel	+61 8 9380 7766		
Fax	+61 8 9380 7733  		
andrew.mcdonald@n...
  
The information in this email, and any attachments, may contain confidential information and is intended solely for the attention and use of the named addressee (s). It must not be disclosed to any person(s) without authorization. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorized to, and must not, disclose, copy, distribute, or retain this message or any part of it. If you have received this communication in error, please notify the sender immediately.




> -----Original Message-----
> From: Maciek Kaminski [mailto:maciejka@t...]
> Sent: Thursday, 10 August 2006 12:18 AM
> To: Yate mailing list
> Subject: [yate] Condition class proposal
> 
> 
> There is a reapearing need in yate for synchronization 
> construct called 
> conditional variables. There is a need for that in extmodule, 
> wavefile 
> like modules (for ThreadedSource cancelation) and others. Here is 
> initial impementation for unix. I am asking windows people to verify 
> whether it is possible to implement the same under windows:
> 
> 
> class YATE_API Condition
> {
>   public:
>    Condition(Mutex *mutex);
>    Condition();
>    ~Condition();
>    void acquire();
>    void release();
>    void wait(int timeout = 0);
>    void notify();
>    void notifyAll();
>   private:
>    Mutex *m_mutex;
>    pthread_cond_t m_cond;
>    int m_waiting;
>    bool cleanup;
> };
> 
> 
> Condition::Condition(Mutex *mutex)
>    :m_mutex(mutex), m_cond(),
>     m_waiting(0), cleanup(false)
> {
>    ::pthread_cond_init(&m_cond, NULL);
> }
> 
> Condition::Condition()
>    :m_mutex(0), m_waiting(0), cleanup(true)
> {
>    m_mutex = new Mutex();
>    ::pthread_cond_init(&m_cond, NULL);
> }
> 
> Condition::~Condition() {
>    if(cleanup)
>      delete m_mutex;
>    pthread_cond_destroy(&m_cond);
> }
> 
> void Condition::acquire() {
>    m_mutex->lock();
> }
> 
> void Condition::release() {
>    m_mutex->unlock();
> }
> 
> void Condition::wait(int timeout) {
>    m_waiting++;
>    Debug(DebugAll,"Condition::wait() on condition [%p]",this);
>    ::pthread_cond_wait(&m_cond, &m_mutex->m_private->m_mutex);
>    Debug(DebugAll,"Condition::wait() succedded on condition 
> [%p]",this);
>    m_waiting--;
> }
> 
> void Condition::notify() {
>    Debug(DebugAll,"Condition::notify() on condition [%p]",this);
>    ::pthread_cond_signal(&m_cond);
> }
> 
> void Condition::notifyAll() {
>    for(int i = m_waiting; i-- > 0; notify());
> }
> 
> mk
>