44using namespace std::chrono_literals;
58 bool Start(
bool exc_info =
false)
67 catch (std::exception& ex) {
69 std::cerr <<
"StoppableThread::Start() exception: " << ex.what() << std::endl;
73 std::cerr <<
"StoppableThread::Start() unknow exception catched" << std::endl;
82 void Stop(
bool wait =
false)
109 template <
class Rep,
class Period>
110 void Sleep(
const std::chrono::duration<Rep, Period> &d)
112 std::this_thread::sleep_for(d);
A stoppable C++11 thread implementation.
virtual void Run()=0
Pure virtual stopable worker function of thread, use the test StopRequested() to check if it should s...
void Sleep(const std::chrono::duration< Rep, Period > &d)
Sleep for the given duration, use literals like 1s, 100ms, 10us.
bool Running()
Returns the current state of the thread.
bool Start(bool exc_info=false)
Start the thread.
virtual ~StoppableThread()=default
void RunInternal()
Internal thread function.
void Stop(bool wait=false)
Stop the thread, needs call(s) to StopRequested() in the Run() worker function to check for the stop ...
bool StopRequested()
Returns if a stop was requested.
StoppableThread()=default
std::atomic_bool m_running