Could be that you can’t initialize the Condition with true and instead set test to true in the action function. TBH, I always forget how Condition works…
Personally I tend to use CondVar because the semantics are more clear to me. Just don’t forget the boolean check in the call to wait!
I have tried to do away with the boolean check in wait as I don’t understand why it is needed - but it definitely seems to be necessary - can you explain why that is?
So why is it not sufficient to have the action signal the condvar which should wake up the thread sitting on wait (without a predicate) which can then check if the plugin is open. But when I try it like that it seems wait block forever - but why is that?
You are talking about CondVar and not Condition, right? Classic condition variables always need a predicate because they do not ‘know’ that they have been signalled. If the async operation is very fast, the callback may be scheduled before the main routine calls wait. In this case, signalOne has no effect because the routine isn’t waiting yet. Without the predicate, the subsequent wait call would block forever because nobody will signal it. With the predicate, it will just return immediately without waiting.
Yeah, that’s how Condition is supposed to be used. I got a bit confused there.
I think, though, that without a timeout, it’s impossible to advance beyond the wait-with-predicate e.g. cv.wait { done } until the predicate is true…? So the error handling branch would never be reached.
CondVar can:
wait without a predicate – always advances when signaled, even if the async op was unsuccessful;
wait with a predicate, and no timeout – no way past the barrier except success (failure means the thread blocks forever);
wait with a predicate and timeout – the thread can advance right away on success, or after the timeout on failure.