Libftpp
A modern C++ library
thread.cpp
Go to the documentation of this file.
1 #include "thread.hpp"
2 
4 {
5  this->stop();
6 }
7 Thread::Thread(const std::string& name, std::function<void()> funcToExecute)
8  : _funct(std::move(funcToExecute))
9 {
10  _stream.setPrefix(name + ": ");
11 }
12 
14 {
15  if (_t.joinable())
16  {
17  _stream << "[ERROR] Thread already running [ERROR]";
18  stop();
19  }
20  _t = std::thread(_funct);
21 }
22 
24 {
25  if (!_t.joinable())
26  return;
27  _t.join();
28 }
void setPrefix(const std::string &prefix)
void start()
Definition: thread.cpp:13
~Thread()
Definition: thread.cpp:3
Thread(const std::string &name, std::function< void()> funcToExecute)
Definition: thread.cpp:7
void stop()
Definition: thread.cpp:23