Skip to content

Commit

Permalink
Don't throw away thread object
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Aug 31, 2023
1 parent 3f67335 commit a2e7444
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Source/Objects/ofxOfeliaMessageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TimerThread
if (!running)
{
running = true;
std::thread([this, intervalMillis]() {
timerThread = std::thread([this, intervalMillis]() {
while (running)
{
auto start = std::chrono::high_resolution_clock::now();
Expand All @@ -47,19 +47,21 @@ class TimerThread
if (sleepTime > std::chrono::milliseconds::zero())
std::this_thread::sleep_for(sleepTime);
}
}).detach();
});
}
}

void stop()
{
running = false;
timerThread.join();
}

virtual void timerCallback() = 0;

private:
bool running;
std::thread timerThread;
std::atomic<bool> running;
};


Expand Down

0 comments on commit a2e7444

Please sign in to comment.