File tree Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,37 @@ class Foo {
6
6
Foo () {
7
7
}
8
8
9
+ void first (function<void ()> printFirst) {
10
+ // printFirst() outputs "first". Do not change or remove this line.
11
+ printFirst ();
12
+ p1_.set_value ();
13
+ }
14
+
15
+ void second (function<void ()> printSecond) {
16
+ p1_.get_future ().wait ();
17
+ // printSecond() outputs "second". Do not change or remove this line.
18
+ printSecond ();
19
+ p2_.set_value ();
20
+ }
21
+
22
+ void third (function<void ()> printThird) {
23
+ p2_.get_future ().wait ();
24
+ // printThird() outputs "third". Do not change or remove this line.
25
+ printThird ();
26
+ }
27
+
28
+ private:
29
+ promise<void > p1_;
30
+ promise<void > p2_;
31
+ };
32
+
33
+ // Time: O(n)
34
+ // Space: O(1)
35
+ class Foo2 {
36
+ public:
37
+ Foo2 () {
38
+ }
39
+
9
40
void first (function<void ()> printFirst) {
10
41
{
11
42
unique_lock<mutex> l (m_);
@@ -46,9 +77,9 @@ class Foo {
46
77
47
78
// Time: O(n)
48
79
// Space: O(1)
49
- class Foo2 {
80
+ class Foo3 {
50
81
public:
51
- Foo2 () {
82
+ Foo3 () {
52
83
m1_.lock ();
53
84
m2_.lock ();
54
85
}
You can’t perform that action at this time.
0 commit comments