You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
voidTrigger(boolNotifyAll = false, int SignalValue = 1)
141
142
{
142
143
// The thread that intends to modify the variable has to
143
144
// * acquire a std::mutex (typically via std::lock_guard)
@@ -146,17 +147,25 @@ class Signal
146
147
{
147
148
// std::condition_variable works only with std::unique_lock<std::mutex>
148
149
std::lock_guard<std::mutex> Lock(m_Mutex);
149
-
m_bIsTriggered = true;
150
+
VERIFY(SignalValue != 0, "Signal value must not be 0");
151
+
VERIFY(m_SignalledValue == 0 && m_NumThreadsAwaken == 0, "Not all threads have been awaken since the signal was triggered last time, or the signal has not been reset");
152
+
m_SignalledValue = SignalValue;
150
153
}
151
154
// Unlocking is done before notifying, to avoid waking up the waiting
152
155
// thread only to block again (see notify_one for details)
153
-
if(bNotifyAll)
156
+
if(NotifyAll)
154
157
m_CondVar.notify_all();
155
158
else
156
159
m_CondVar.notify_one();
157
160
}
158
161
159
-
voidWait()
162
+
// WARNING!
163
+
// If multiple threads are waiting for a signal in an infinite loop,
164
+
// autoresetting the signal does not guarantee that one thread cannot
165
+
// go through the loop twice. In this case, every thread must wait for its
166
+
// own auto-reset signal or the threads must be blocked by another signal
167
+
168
+
intWait(bool AutoReset = false, int NumThreadsWaiting = 0)
160
169
{
161
170
// Any thread that intends to wait on std::condition_variable has to
162
171
// * acquire a std::unique_lock<std::mutex>, on the SAME MUTEX as used to protect the shared variable
@@ -166,26 +175,45 @@ class Signal
166
175
// the thread is awakened, and the mutex is atomically reacquired:
167
176
// - The thread should then check the condition and resume waiting if the wake up was spurious.
168
177
std::unique_lock<std::mutex> Lock(m_Mutex);
169
-
if (!m_bIsTriggered)
178
+
// It is safe to check m_SignalledValue since we are holding
0 commit comments