BeamMP-Server/include/IThreaded.h
2024-01-19 14:42:21 +01:00

24 lines
533 B
C++

#pragma once
#include <boost/thread/scoped_thread.hpp>
#include <thread>
// pure virtual class to be inherited from by classes which intend to be threaded
class IThreaded {
public:
IThreaded()
// invokes operator() on this object
: mThread() { }
virtual ~IThreaded() noexcept {
mThread.interrupt();
}
virtual void Start() final {
mThread = boost::scoped_thread<>([this] { (*this)(); });
}
virtual void operator()() = 0;
protected:
boost::scoped_thread<> mThread {};
};