gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
WaitingThread Class Reference

#include <Thread.H>

Inheritance diagram for WaitingThread:
[legend]
Collaboration diagram for WaitingThread:
[legend]

Public Member Functions

virtual ~WaitingThread (void)
 
- Public Member Functions inherited from ThreadedMethod
virtual void * threadMain (void)=0
 
virtual int run (int priority=0)
 
- Public Member Functions inherited from Thread
 Thread (void)
 
virtual ~Thread (void)
 
void * stop (void)
 
int run (void *(*start_routine)(void *), void *data, int priority=0)
 
int setPriority (pthread_attr_t *attributes, int priority)
 
int getPriority ()
 
void * meetThread (void)
 
void exit (void *retVal)
 
bool running ()
 

Public Attributes

Cond cond
 

Detailed Description

Class for inter thread signaling and synchronisation.

Synchronisation is performed in the following manner :

class WaitingThreadTest : public WaitingThread {
public:
void *threadMain(void){ // This is the method to execute in the thread
cout<<"WaitingThreadTest : I have been signalled "<<endl;
return NULL;
}
};
// This is an example from the main thread ... shows you how to signal the waiting thread.
WaitingThreadTest waitingThread;
waitingThread.run(); // start the waiting thread - and give a second to start
sleep(1);
waitingThread.cond.lock(); // lock the mutex, indicate the condition and wake the thread.
waitingThread.cond.signal(); // Wake the WaitingThread
waitingThread.cond.unLock(); // Unlock so the WaitingThread can continue.

If you need a Boolean test, then construct like so :

class WaitingThreadTest : public WaitingThread {
public:
bool ready;
WaitingThreadTest(){
ready=false;
}
void *threadMain(void){
while (running()){ // while this thread is running
while (!ready)
cout<<"WaitingThreadTest: I have been signalled and ready is true!"<<endl;
ready=false;
}
return NULL;
}
};
// in your main thread
WaitingThreadTest waitingThread;
waitingThread.run(); // start the waiting thread - and give a second to start
sleep(1);
waitingThread.cond.lock(); // lock the mutex, indicate the condition and wake the thread.
waitingThread.ready=true;
waitingThread.cond.signal(); // Wake the WaitingThread
waitingThread.cond.unLock(); // Unlock so the WaitingThread can continue.
Examples:
ThreadTest.C.

Definition at line 439 of file Thread.H.

Constructor & Destructor Documentation

◆ ~WaitingThread()

virtual WaitingThread::~WaitingThread ( void  )
inlinevirtual

Definition at line 443 of file Thread.H.

Here is the call graph for this function:

Member Data Documentation

◆ cond

Cond WaitingThread::cond

Definition at line 441 of file Thread.H.


The documentation for this class was generated from the following file:
gtkIOStream: WaitingThread Class Reference
GTK+ IOStream  Beta