cgv
thread.h
1 #pragma once
2 
3 #include "mutex.h"
4 #include <iostream>
5 
6 #include "lib_begin.h"
7 
8 namespace cgv {
9  namespace os {
10 
12 typedef unsigned long long thread_id_type;
13 
38 class CGV_API thread
39 {
40 protected:
41  void *thread_ptr;
42  bool stop_request;
43  bool running;
44  bool delete_after_termination;
45  static void* execute_s(void* args);
47  void execute();
48 public:
50  thread();
52  virtual ~thread();
54  void start(bool _delete_after_termination = false);
56  virtual void run()=0;
58  static void wait_for_signal(condition_mutex& cm);
60  static void wait_for_signal_with_lock(condition_mutex& cm);
62  static bool wait_for_signal_or_timeout(condition_mutex& cm, unsigned millisec);
64  static bool wait_for_signal_or_timeout_with_lock(condition_mutex& cm, unsigned millisec);
66  static void wait(unsigned millisec);
70  void stop();
72  void kill();
75  void wait_for_completion();
77  inline bool is_running() { return running; }
79  inline bool have_stop_request() { return stop_request; }
81  static thread_id_type get_current_thread_id();
83  thread_id_type get_id() const;
84 };
85 
87 extern CGV_API thread* start_in_thread(void (*func)(thread_id_type), bool _delete_after_termination = false);
88 
89  }
90 }
91 
92 #include <cgv/config/lib_end.h>
cgv::os::thread::is_running
bool is_running()
return true if thread is running
Definition: thread.h:77
cgv::os::thread
Definition: thread.h:39
cgv::os::thread::have_stop_request
bool have_stop_request()
check if there is a stop request
Definition: thread.h:79
cgv::os::condition_mutex
Definition: mutex.h:42
cgv::os::thread::run
virtual void run()=0
thread function to override
cgv
the cgv namespace
Definition: vr_calib.cxx:9