examples/cpp-multithreaded: running flag is atomic
This commit is contained in:
parent
4b20c5b045
commit
178671a7bd
|
@ -6,6 +6,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <atomic>
|
||||||
#include "../../ui.h"
|
#include "../../ui.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ uiMultilineEntry *e;
|
||||||
condition_variable cv;
|
condition_variable cv;
|
||||||
mutex m;
|
mutex m;
|
||||||
thread *timeThread;
|
thread *timeThread;
|
||||||
volatile bool running = true;
|
atomic<bool> running(true);
|
||||||
|
|
||||||
void sayTime(void *data)
|
void sayTime(void *data)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +27,7 @@ void sayTime(void *data)
|
||||||
void threadproc(void)
|
void threadproc(void)
|
||||||
{
|
{
|
||||||
unique_lock<mutex> ourlock(m);
|
unique_lock<mutex> ourlock(m);
|
||||||
while (running) {
|
while (running.load()) {
|
||||||
cv.wait_for(ourlock, chrono::seconds(1));
|
cv.wait_for(ourlock, chrono::seconds(1));
|
||||||
time_t t;
|
time_t t;
|
||||||
char *base;
|
char *base;
|
||||||
|
|
Loading…
Reference in New Issue