Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Barrier.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <condition_variable>
35#include <cstdint>
36#include <mutex>
37
38namespace ogdf {
39
41
48class Barrier {
49 std::condition_variable m_allThreadsReachedSync;
51
52 uint32_t m_threadCount;
54 uint32_t m_syncNumber;
55
56public:
58 explicit Barrier(uint32_t numThreads) : m_threadCount(numThreads) {
60 m_syncNumber = 0;
61 }
62
64
68 void threadSync() {
69 std::unique_lock<std::mutex> lk(m_numThreadsReachedSyncLock);
70
71 uint32_t syncNr = m_syncNumber;
75 m_allThreadsReachedSync.notify_all();
77
78 } else {
79 m_allThreadsReachedSync.wait(lk, [syncNr, this] { return syncNr != m_syncNumber; });
80 }
81 }
82};
83
84}
Representation of a barrier.
Definition Barrier.h:48
Barrier(uint32_t numThreads)
Creates a barrier for a group of numThreads threads.
Definition Barrier.h:58
std::mutex m_numThreadsReachedSyncLock
Definition Barrier.h:50
uint32_t m_threadCount
the number of threads in the group.
Definition Barrier.h:52
uint32_t m_numThreadsReachedSync
number of htreads that reached current synchronization point.
Definition Barrier.h:53
uint32_t m_syncNumber
number of current synchronization point.
Definition Barrier.h:54
void threadSync()
Synchronizes the threads in the group.
Definition Barrier.h:68
std::condition_variable m_allThreadsReachedSync
Definition Barrier.h:49
The namespace for all OGDF objects.