diff --git a/leetcode/1114.print-in-order/main.cpp b/leetcode/1114.print-in-order/main.cpp deleted file mode 100644 index 589de05b..00000000 --- a/leetcode/1114.print-in-order/main.cpp +++ /dev/null @@ -1,63 +0,0 @@ - -#include - -#include -#include -#include - -void printFirst() { - printf("first"); -} - -void printSecond() { - printf("second"); -} - -void printThird() { - printf("third"); -} - -class Foo { - public: - Foo() : counter_(0) {} - - void first(std::function printFirst) { - printFirst(); - counter_.store(1, std::memory_order_seq_cst); - } - - void second(std::function printSecond) { - while (counter_.load(std::memory_order_seq_cst) != 1) { - // empty - } - printSecond(); - counter_.store(2, std::memory_order_seq_cst); - } - - void third(std::function printThird) { - while (counter_.load(std::memory_order_seq_cst) != 2) { - // empty - } - printThird(); - } - - private: - std::atomic_int counter_; -}; - -int main() { - Foo foo; - std::thread a([&foo]() { - foo.first(printFirst); - }); - std::thread b([&foo]() { - foo.second(printSecond); - }); - std::thread c([&foo]() { - foo.third(printThird); - }); - a.join(); - b.join(); - c.join(); - return 0; -}