8 февр. 2010 г.
2 февр. 2010 г.
Spurious wakeup
There are some freaky things in multithreads programming. One of the is so called "Spurious wakeup".
So, seemly valid code:
void wait_for_data() {
need to be corrected:
So, seemly valid code:
void wait_for_data() {
boost::mutex::scoped_lock lock(the_mutex);
if(the_queue.empty()) {
the_condition_variable.wait(lock); }
}
if(the_queue.empty()) {
the_condition_variable.wait(lock); }
}
need to be corrected:
void wait_for_data()
{
boost::mutex::scoped_lock lock(the_mutex);
while(the_queue.empty()) {
{
boost::mutex::scoped_lock lock(the_mutex);
while(the_queue.empty()) {
the_condition_variable.wait(lock); }}
links:
links:
Подписаться на:
Сообщения (Atom)