File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,20 @@ Platform::~Platform()
63
63
*/
64
64
void Platform::stop ()
65
65
{
66
+ // we modify the _running, it may be that the other thread has a lock
67
+ // to protect this variable, although it is attomic, we need to respect
68
+ // this lock. E.g. run uses a lock before it enters the _condition.wait()
69
+ // if we don't take a lock here, we may update running and call
70
+ // notify before the other thread called wait, but already checked if
71
+ // we were running. In that case the other thread will never be notified.
72
+ std::unique_lock<std::mutex> lock (_mutex);
73
+
66
74
// we set it to false, but if the old value was not true then we leap out
67
75
if (!_running.exchange (false )) return ;
76
+
77
+ // we need to release the lock over here, so the other thread can move
78
+ // on.
79
+ lock.unlock ();
68
80
69
81
// signal the thread in case it is waiting for input
70
82
_condition.notify_one ();
You can’t perform that action at this time.
0 commit comments