I have two threads and a flag that gets set by the second thread. I could use an atomic_bool
, but I want to be able to wait* for the flag being set on the first thread. How can I do that?
I can't use a condition_variable
I guess, because if the second thread calls notify_one
before the first thread starts waiting, the thread won't wake up.
Also, checking if the flag has already been set should be reasonably fast. I guess this should be rather simple, but I'm just stuck, so I'm asking here. Thanks in advance.
*Edit: Block of course, not busy-wait. Sorry if that wasn't clear.