2024每日刷题(179)
Leetcode—1114. 按序打印
C++实现代码
class Foo {
public:
Foo() {
firstMutex.lock();
secondMutex.lock();
}
void first(function<void()> printFirst) {
// printFirst() outputs "first". Do not change or remove this line.
printFirst();
firstMutex.unlock();
}
void second(function<void()> printSecond) {
// printSecond() outputs "second". Do not change or remove this line.
firstMutex.lock();
printSecond();
secondMutex.unlock();
}
void third(function<void()> printThird) {
// printThird() outputs "third". Do not change or remove this line.
secondMutex.lock();
printThird();
}
private:
mutex firstMutex;
mutex secondMutex;
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!