File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 6
6
#include < string.h>
7
7
#include < stdlib.h>
8
8
#include < time.h>
9
+ #include < atomic>
9
10
#include " ../../ui.h"
10
11
using namespace std ;
11
12
12
13
uiMultilineEntry *e;
13
14
condition_variable cv;
14
15
mutex m;
15
- unique_lock<mutex> ourlock (m);
16
16
thread *timeThread;
17
+ atomic<bool > running (true );
17
18
18
19
void sayTime (void *data)
19
20
{
@@ -25,8 +26,9 @@ void sayTime(void *data)
25
26
26
27
void threadproc (void )
27
28
{
28
- ourlock.lock ();
29
- while (cv.wait_for (ourlock, chrono::seconds (1 )) == cv_status::timeout) {
29
+ unique_lock<mutex> ourlock (m);
30
+ while (running.load ()) {
31
+ cv.wait_for (ourlock, chrono::seconds (1 ));
30
32
time_t t;
31
33
char *base;
32
34
char *s;
@@ -41,6 +43,10 @@ void threadproc(void)
41
43
42
44
int onClosing (uiWindow *w, void *data)
43
45
{
46
+ {
47
+ unique_lock<mutex> l (m);
48
+ running = false ;
49
+ }
44
50
cv.notify_all ();
45
51
// C++ throws a hissy fit if you don't do this
46
52
// we might as well, to ensure no uiQueueMain() gets in after uiQuit()
@@ -81,8 +87,6 @@ int main(void)
81
87
82
88
uiBoxAppend (b, uiControl (e), 1 );
83
89
84
- // timeThread needs to lock ourlock itself - see http://stackoverflow.com/a/34121629/3408572
85
- ourlock.unlock ();
86
90
timeThread = new thread (threadproc);
87
91
88
92
uiWindowOnClosing (w, onClosing, NULL );
You can’t perform that action at this time.
0 commit comments