File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Foo
2
+ {
3
+ public:
4
+ Foo ()
5
+ :one_(false ),
6
+ second_ (false )
7
+ {
8
+
9
+ }
10
+
11
+ void first (function<void ()> printFirst)
12
+ {
13
+ unique_lock<mutex> lock (mutex_);
14
+ printFirst ();
15
+ one_ = true ;
16
+ condition_.notify_all ();
17
+ }
18
+
19
+ void second (function<void ()> printSecond)
20
+ {
21
+ unique_lock<mutex> lock (mutex_);
22
+ condition_.wait (lock, [this ]() { return one_; });
23
+ printSecond ();
24
+ second_ = true ;
25
+ condition_.notify_all ();
26
+ }
27
+
28
+ void third (function<void ()> printThird)
29
+ {
30
+ unique_lock<mutex> lock (mutex_);
31
+ condition_.wait (lock, [this ]() { return second_; });
32
+ printThird ();
33
+ }
34
+ private:
35
+ condition_variable condition_;
36
+ mutex mutex_;
37
+ bool one_;
38
+ bool second_;
39
+ };
You can’t perform that action at this time.
0 commit comments