-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintinOrder.cpp
More file actions
39 lines (31 loc) · 857 Bytes
/
printinOrder.cpp
File metadata and controls
39 lines (31 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Source: https://leetcode.com/problems/print-in-order/
// Author: Miao Zhang
// Date: 2021-04-12
class Foo {
public:
Foo() {
first_.lock();
second_.lock();
}
void first(function<void()> printFirst) {
// printFirst() outputs "first". Do not change or remove this line.
printFirst();
first_.unlock();
}
void second(function<void()> printSecond) {
// printSecond() outputs "second". Do not change or remove this line.
first_.lock();
printSecond();
first_.unlock();
second_.unlock();
}
void third(function<void()> printThird) {
// printThird() outputs "third". Do not change or remove this line.
second_.lock();
printThird();
second_.unlock();
}
private:
std::mutex first_;
std::mutex second_;
};