2 #include "common_std_thread.h"
14 delete_after_termination =
false;
21 delete_after_termination = _delete_after_termination;
23 std::thread*& std_thread_ptr =
reinterpret_cast<std::thread*&
>(thread_ptr);
26 std_thread_ptr =
new std::thread(&cgv::os::thread::execute_s,
this);
34 Condition& c = *((Condition*&) cm.pcond);
41 Condition& c = *((Condition*&) cm.pcond);
42 std::chrono::milliseconds dura(millisec);
43 return c.cv.wait_for(c.ul, dura) == std::cv_status::no_timeout;
63 void* thread::execute_s(
void* args)
67 if (t->delete_after_termination)
82 std::chrono::milliseconds dura(millisec);
83 std::this_thread::sleep_for(dura);
90 std::thread* std_thread_ptr =
reinterpret_cast<std::thread*
>(thread_ptr);
91 std_thread_ptr->join();
100 std::thread*& std_thread_ptr =
reinterpret_cast<std::thread*&
>(thread_ptr);
101 std_thread_ptr->detach();
102 delete std_thread_ptr;
113 std::thread& t = *((std::thread*&) thread_ptr);
124 std::thread* std_thread_ptr =
reinterpret_cast<std::thread*
>(thread_ptr);
125 delete std_thread_ptr;
133 std::thread::id
id = std::this_thread::get_id();
134 return (
long long&) id;
140 std::thread* std_thread_ptr =
reinterpret_cast<std::thread*
>(thread_ptr);
141 std::thread::id
id = std_thread_ptr->get_id();
142 return (
long long&) id;
145 class function_thread :
public thread
148 void (*func)(thread_id_type);
150 function_thread(
void (*_func)(thread_id_type))
161 thread* start_in_thread(
void (*func)(thread_id_type),
bool _delete_after_termination)
163 thread* ft =
new function_thread(func);
164 ft->start(_delete_after_termination);
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....
Definition: thread_pthread.h:45
void unlock()
unlock the mutex
Definition: mutex_pthread.h:46
void start(bool _delete_after_termination=false)
start the implemented run() method (asynchronly) and destruct the thread object
Definition: thread_pthread.h:23
void lock()
lock the mutex (if the mutex is already locked, the caller is blocked until the mutex becomes availab...
Definition: mutex_pthread.h:40
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 w...
Definition: thread_pthread.h:39
void wait_for_completion()
join the current thread
Definition: thread_pthread.h:98
void execute()
executes the run method
Definition: thread_pthread.h:62
void stop()
Definition: thread_pthread.h:78
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....
Definition: thread_std_thread.h:55
static void wait(unsigned millisec)
wait the given number of milliseconds
Definition: thread_pthread.h:69
static thread_id_type get_current_thread_id()
return the id of the currently executed thread
Definition: thread_pthread.h:119
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,...
Definition: thread_std_thread.h:39
void kill()
kill a running thread
Definition: thread_pthread.h:88
virtual ~thread()
standard destructor (a running thread will be killed)
Definition: thread_pthread.h:106
virtual void run()=0
thread function to override
thread()
create the thread
Definition: thread_pthread.h:14
the cgv namespace
Definition: vr_calib.cxx:9
thread_id_type get_id() const
return id of this thread
Definition: thread_pthread.h:125