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 ArticleAnswer 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 ArticleAnswer 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 ArticleWaiting 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
More Pages to Explore .....