Thread barrier for synchronizing multiple threads
| 95 | |
| 96 | // Thread barrier for synchronizing multiple threads |
| 97 | class ThreadBarrier { |
| 98 | public: |
| 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 | |
| 114 | private: |
| 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 |
| 123 | struct ExpectedStats { |
nothing calls this directly
no outgoing calls
no test coverage detected