task_queue ()
{
pthread_mutex_init (&fooLock, NULL);
- pthread_cond_init (&fooCond, NULL);
+ pthread_cond_init (&fooCond1, NULL);
+ pthread_cond_init (&fooCond2, NULL);
}
~task_queue ()
{
pthread_mutex_destroy (&fooLock);
- pthread_cond_destroy (&fooCond);
+ pthread_cond_destroy (&fooCond1);
+ pthread_cond_destroy (&fooCond2);
}
list<int> foo;
pthread_mutex_t fooLock;
- // This code uses a special case that allows us to use just one
- // condition variable - in general, don't use this idiom unless you
- // know what you are doing. ;-)
- pthread_cond_t fooCond;
+ pthread_cond_t fooCond1;
+ pthread_cond_t fooCond2;
};
void*
{
pthread_mutex_lock (&tq.fooLock);
while (tq.foo.size () >= max_size)
- pthread_cond_wait (&tq.fooCond, &tq.fooLock);
+ pthread_cond_wait (&tq.fooCond1, &tq.fooLock);
tq.foo.push_back (num++);
- pthread_cond_signal (&tq.fooCond);
+ pthread_cond_signal (&tq.fooCond2);
pthread_mutex_unlock (&tq.fooLock);
}
return 0;
{
pthread_mutex_lock (&tq.fooLock);
while (tq.foo.size () == 0)
- pthread_cond_wait (&tq.fooCond, &tq.fooLock);
+ pthread_cond_wait (&tq.fooCond2, &tq.fooLock);
if (tq.foo.front () != num++)
abort ();
tq.foo.pop_front ();
- pthread_cond_signal (&tq.fooCond);
+ pthread_cond_signal (&tq.fooCond1);
pthread_mutex_unlock (&tq.fooLock);
}
return 0;