MCPcopy Create free account
hub / github.com/Compaile/ctrack / ThreadBarrier

Class ThreadBarrier

test/test_helpers.hpp:97–120  ·  view source on GitHub ↗

Thread barrier for synchronizing multiple threads

Source from the content-addressed store, hash-verified

95
96// Thread barrier for synchronizing multiple threads
97class ThreadBarrier {
98public:
99 explicit ThreadBarrier(size_t count) : threshold(count), count(count), generation(0) {}
100
101 void wait() {
102 std::unique_lock<std::mutex> lock(mutex);
103 auto gen = generation;
104
105 if (--count == 0) {
106 generation++;
107 count = threshold;
108 cond.notify_all();
109 } else {
110 cond.wait(lock, [this, gen] { return gen != generation; });
111 }
112 }
113
114private:
115 std::mutex mutex;
116 std::condition_variable cond;
117 size_t threshold;
118 size_t count;
119 size_t generation;
120};
121
122// Calculate expected statistics for a series of sleep times
123struct ExpectedStats {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected