From aa67cb4f88bf9f04f4bc34070f79f4eb2806be49a63157294b607717a17d89c2 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 29 Oct 2026 11:52:14 +1000 Subject: [PATCH] before practice 3 --- .zed/debug.json | 7 +++++++ src/barrier.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/main.cpp | 10 +++++----- 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 .zed/debug.json create mode 100644 src/barrier.cpp diff --git a/.zed/debug.json b/.zed/debug.json new file mode 100644 index 0000000..0f93857 --- /dev/null +++ b/.zed/debug.json @@ -0,0 +1,7 @@ +// Project-local debug tasks +// +// For more documentation on how to configure debug tasks, +// see: https://zed.dev/docs/debugger +[ + +] diff --git a/src/barrier.cpp b/src/barrier.cpp new file mode 100644 index 0000000..3774c95 --- /dev/null +++ b/src/barrier.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +class Barrier{ + std::mutex mtx; + std::condition_variable cv; + std::size_t count=0; + std::size_t max_count=0; + bool flushing = false; + Barrier (size_t max_count){ + max_count=max_count; + } + void arrive_and_wait(){ + std::unique_lock lock(mtx); + while(flushing) + cv.wait(lock); + if(++count