class ThreadCondition

A thread condition More...

Full nameArts::ThreadCondition
Definition#include <arts/thread.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods


Detailed Description

A thread condition

Thread conditions are used to let a different thread know that a certain condition might have changed. For instance, if you have a thread that waits until a counter exceeds a limit, the thread would look like this:


 class WaitCounter : public Arts::Thread 
 {
   int counter;
   Arts::Mutex mutex;
   Arts::ThreadCondition cond;
 
 public:
   WaitCounter() : counter(0) {}

   void run() {  // run will terminate once the counter reaches 20
     mutex.lock();
     while(counter < 20)
       cond.wait(mutex);
     mutex.unlock();
   }

   void inc() {  // inc will increment the counter and indicate the change
     mutex.lock();
     counter++;
     cond.wakeOne();
     mutex.unlock();
   }
 };

 ThreadCondition ()

ThreadCondition

 ~ThreadCondition ()

~ThreadCondition

[virtual]

inline void  wakeOne ()

wakeOne

wakes one waiting thread

inline void  wakeAll ()

wakeAll

wakes all waiting threads

inline void  wait (Mutex& mutex)

wait

Waits until the condition changes. You will need to lock the mutex before calling this. Internally it will unlock the mutex (to let others change the condition), and relock it once the wait succeeds.


Generated by: stefan on stefan on Sat Jun 2 23:13:28 2001, using kdoc 2.0a53.