From b78fbc64d8fc9d64e2e7a952f252afa95e5bb6eb Mon Sep 17 00:00:00 2001 From: Xu Shaohua Date: Fri, 15 Dec 2023 07:30:06 +0800 Subject: [PATCH] leetcode: Remove cpp impl of print-in-order --- leetcode/1114.print-in-order/main.cpp | 63 --------------------------- 1 file changed, 63 deletions(-) delete mode 100644 leetcode/1114.print-in-order/main.cpp 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; -}