Quantcast
Channel: Waiting for an atomic_bool - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Waiting for an atomic_bool

$
0
0

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.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images