Click to See Complete Forum and Search --> : Thread question, does this code look OK?


Jim44
September 1st, 2005, 02:28 PM
pthread_mutex_t *out_queue_mutex;
pthread_cond_t *out_queue_chk_cv;
...
out_queue_mutex = new pthread_mutex_t[threadCount];
out_queue_chk_cv = new pthread_cond_t[threadCount];
...
for (int i = 0; i < threadCount; i++) {
pthread_mutex_init (&out_queue_mutex[i], NULL);
pthread_cond_init (&out_queue_chk_cv[i], NULL);
}
...
for (int i = 0; i < threadCount; i++) {
myPthreadMutexLock (&out_queue_mutex[i]);
pthread_cond_signal (&out_queue_chk_cv[i]);
myPthreadMutexUnLock (&out_queue_mutex[i]);
}
...
myPthreadMutexLock (&outputLock);
if (!outputQueue->getCount ()) {
myPthreadMutexUnLock (&outputLock);
cout << me << " startOutputStage sleeping " << endl;
pthread_cond_wait (&out_queue_chk_cv[me], &out_queue_mutex[me]);
// wait for wakeup call
...

I didnt show it all, just the pertinent parts. Do they look OK? This seems to work fine for months and then, well it just doesn't wake up. The last block of code is in a while loop. I know it isn't coming out of the loop.

I'm looking for verification I'm not doing something stupid with my pointers.

Thanks,
Jim.

Marc G
September 1st, 2005, 02:40 PM
[ moved thread ]