Skip to content

Commit 71c520b

Browse files
committed
add explaining comment
1 parent 68bf827 commit 71c520b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

include/reactor-cpp/time_barrier.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ private:
5050
LogicalTime released_time_;
5151
Scheduler* scheduler_;
5252

53+
/*
54+
* Note that we use the main scheduler lock to protect our `released_time_`
55+
* variable. We cannot use a local mutex here that only protects our local
56+
* state. This is, because we also need to use a lock to wait on a condition
57+
* variable. This lock must be the same lock as the one that is used when
58+
* updating the wait condition. (See "An atomic predicate" in
59+
* https://www.modernescpp.com/index.php/c-core-guidelines-be-aware-of-the-traps-of-condition-variables)
60+
*
61+
* Here we have two conditions in which we want to stop the wait:
62+
* 1. When the tag that we are waiting for was released.
63+
* 2. When the given function `abort_waiting` returns true. In a typical usage
64+
* scenario, this would be the case when a new event was scheduled.
65+
*
66+
* We need to make sure that both conditions are updated while holding the
67+
* lock that we use for waiting on the condition variable. Our only option for
68+
* this is to use the global scheduler lock.
69+
*/
5370
public:
5471
LogicalTimeBarrier(Scheduler* scheduler)
5572
: scheduler_(scheduler) {}

0 commit comments

Comments
 (0)