Skip to content

Commit 178671a

Browse files
committed
examples/cpp-multithreaded: running flag is atomic
1 parent 4b20c5b commit 178671a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/cpp-multithread/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#include <string.h>
77
#include <stdlib.h>
88
#include <time.h>
9+
#include <atomic>
910
#include "../../ui.h"
1011
using namespace std;
1112

1213
uiMultilineEntry *e;
1314
condition_variable cv;
1415
mutex m;
1516
thread *timeThread;
16-
volatile bool running = true;
17+
atomic<bool> running(true);
1718

1819
void sayTime(void *data)
1920
{
@@ -26,7 +27,7 @@ void sayTime(void *data)
2627
void threadproc(void)
2728
{
2829
unique_lock<mutex> ourlock(m);
29-
while (running) {
30+
while (running.load()) {
3031
cv.wait_for(ourlock, chrono::seconds(1));
3132
time_t t;
3233
char *base;

0 commit comments

Comments
 (0)