|
cgv
|
#include <thread.h>
Public Member Functions | |
| thread () | |
| create the thread | |
| virtual | ~thread () |
| standard destructor (a running thread will be killed) | |
| void | start (bool _delete_after_termination=false) |
| start the implemented run() method (asynchronly) and destruct the thread object More... | |
| virtual void | run ()=0 |
| thread function to override | |
| void | stop () |
| void | kill () |
| kill a running thread | |
| void | wait_for_completion () |
| join the current thread More... | |
| bool | is_running () |
| return true if thread is running | |
| bool | have_stop_request () |
| check if there is a stop request | |
| thread_id_type | get_id () const |
| return id of this thread | |
Static Public Member Functions | |
| static void | wait_for_signal (condition_mutex &cm) |
| sleep till the signal from the given condition_mutex is sent, lock the mutex first and unlock after waiting More... | |
| static void | wait_for_signal_with_lock (condition_mutex &cm) |
| prefered approach to wait for signal and implemented as { cm.lock(); wait_for_signal(cm); cm.unlock(); } | |
| static bool | wait_for_signal_or_timeout (condition_mutex &cm, unsigned millisec) |
| sleep till the signal from the given condition_mutex is sent or the timeout is reached, lock the mutex first and unlock after waiting | |
| static bool | wait_for_signal_or_timeout_with_lock (condition_mutex &cm, unsigned millisec) |
| prefered approach to wait for signal or the timeout is reached and implemented as { cm.lock(); wait_for_signal_or_timeout(cm,millisec); cm.unlock(); } | |
| static void | wait (unsigned millisec) |
| wait the given number of milliseconds | |
| static thread_id_type | get_current_thread_id () |
| return the id of the currently executed thread | |
Protected Member Functions | |
| void | execute () |
| executes the run method | |
Thread class implementation that uses pthreads internally. To create and run your own thread, follow this example: \begincode class mythread : thread {
void run()
{
no external stop request? while(no_stop_request()) { std::cout << "abc" << std::endl; } }
};
mythread t1;
t1.start(); ... t1.stop();
| void cgv::os::thread::start | ( | bool | _delete_after_termination = false | ) |
| void cgv::os::thread::stop | ( | ) |
try to stop the thread execution via indicating a stop request. The existence of a stop request can be recognized by the no_stop_request() method. This test should be done periodically within the implementation of the run() method, e.g. to leave the execution loop in a clean way.
| void cgv::os::thread::wait_for_completion | ( | ) |
join the current thread
the thread is interpreted as a slave thread and started from another master thread. This method is called from the master thread in order to wait for termination of the slave thread.
|
static |
sleep till the signal from the given condition_mutex is sent, lock the mutex first and unlock after waiting
sleep till the signal from the given condition_mutex is sent