c++ - Control multithreaded flow with condition_variable -
I have not yet wrapped my head around the C ++ 11 multithreading stuff, but I have tried several threads Wait till some event on the main thread and then all continue in one time (processed what happened), and It works ... as long as I do not close some breakpoints and slower things. When I do this, let me go to Maybe I should not use any condition variable ... there is no condition around You are on the right track ... wait re-process it ... until they are closed Pets. Not at all - this is a simple breeding of my problem:
std :: mutex mutex; Std :: condition_variable cv; Std :: thread thread1 ([& amp;] () {std :: unique_lock
Go1! appears and then waiting for
thread2 for
cv.wait . What's wrong
waiting , nor need to keep that data safe Is mutex What should I be doing instead of this?
std :: mutex mutex; Std :: condition_variable cv; Bool go = false; Std :: thread thread1 ([& amp;] () {std :: unique_lock & lt; std :: mutex & gt; lock (mutex); while (go!) Cv.wait (lock); std :: cout & Lt; & lt; "GO1! \ N";}); Std :: Thread Thread 2 ([& amp;] () {std :: unique_lock
Comments
Post a Comment