File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Foo {
2
+ public:
3
+ int count = 0 ;
4
+ mutex mtx;
5
+ condition_variable cv;
6
+ Foo () {
7
+ count = 1 ;
8
+ }
9
+
10
+ void first (function<void ()> printFirst) {
11
+ unique_lock<mutex> lck (mtx);
12
+ // printFirst() outputs "first". Do not change or remove this line.
13
+ printFirst ();
14
+ count = 2 ;
15
+ cv.notify_all ();
16
+ }
17
+
18
+ void second (function<void ()> printSecond) {
19
+ unique_lock<mutex> lck (mtx);
20
+ cv.wait (lck, [this ]() { return count == 2 ;});
21
+ // printSecond() outputs "second". Do not change or remove this line.
22
+ printSecond ();
23
+ count = 3 ;
24
+ cv.notify_all ();
25
+ }
26
+
27
+ void third (function<void ()> printThird) {
28
+ unique_lock<mutex> lck (mtx);
29
+ cv.wait (lck, [this ]() { return count == 3 ;});
30
+ // printThird() outputs "third". Do not change or remove this line.
31
+ printThird ();
32
+ }
33
+ };
You can’t perform that action at this time.
0 commit comments