Fabian Sturm
Hi!
I have a quite simple problem, but I still lack a nice implementation in C++ with boost.
My problem is, that I have two threads A and B and thread A needs some information that B will calculate at runtime. Therefore I need some kind of synchronization.
So my first attempt was to use a mutex and a condition variable:
Thread A:
boost::thread::mutex::scoped_lock lock ( mMutex ); mConditionVar.wait ( lock );
Thread B:
mConditionVar.notify_one ();
Correct way to use condvar is the following: Thread A: mutex::scoped_lock lock(mutex); while (!dataCalculated) condvar.wait(lock); Thread B: mutex::scoped_lock lock(mutex); dataCalculated = true; condvar.notify_one(); Instead of 'while' loop you can use condition::wait with a predicate: Thread A: mutex::scoped_lock lock(mutex); condvar.wait(lock, var(dataCalculated)); Regards, Roman Perepelitsa.