Quantcast
Channel: Waiting for an atomic_bool - Stack Overflow
Browsing latest articles
Browse All 4 View Live

Answer by Pete Becker for Waiting for an atomic_bool

bool go = false;std::mutex mtx;std::condition_variable cnd;// waiting thread:std::unique_lock<std::mutex> lck(mtx);while (!go) cnd.wait(lock);// when we get here we know that go is true, and we...

View Article



Answer by cooky451 for Waiting for an atomic_bool

With the help of cbreak and Ravadre (comments) I got from here:int main(){ std::mutex m; std::condition_variable cv; std::thread t([&] { std::this_thread::sleep_for(std::chrono::seconds(1));...

View Article

Answer by phoeagon for Waiting for an atomic_bool

What exactly is your platform? On posix-compliant platforms we use sem_t semaphore; sem_init( &semaphore , 0 , x );to get a semaphore with initial value of x. Then with sem_wait(&semaphore );...

View Article

Waiting for an atomic_bool

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...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images