Du kannst eine Thread Funktion in einer Klasse nutzen. Hier ein Bsp.
Code:Test::Test() { // create the worker thread m_run.store(true); m_thread = std::thread(std::bind(&Test::execute, this)); } Test::~Test() { m_run.store(false); if (m_thread.joinable() { m_thread.join(); } } void Test::execute() { while (m_run.load()) { } } class Test { public: Test(); ~Test(); private: // the thread function void execute(); // the thread std::atomic<bool> m_run; std::thread m_thread; };
Lesezeichen