- 论坛徽章:
- 0
|
//n 个线程
pthread_mutex_lock(&(pool->queue_lock);
if (!pool->Cur_queue_size )
{
pthread_cond_wait (&(pool->queue_ready), &(pool->queue_lock));
}
//一些操作后
pthread_mutex_unlock(&(pool->queue_lock));
另外一个线程
while(1)
{
if (pthread_mutex_trylock (&(pool->queue_lock)) == 0)
{
//一些操作后
pthread_mutex_unlock (&(pool->queue_lock));
pthread_cond_signal (&(pool->queue_ready));
break;
}
else
{
printf("加锁失败\n");
//pthread_mutex_unlock (&(pool->queue_lock));
}
}
上面的程序刚启动时第一次执行成功(即while没有加锁失败),第二次while 这个线程加锁失败,处在死循环中,
我在加锁失败时又解了一次锁,但程序又卡在pthread_cond_signal (&(pool->queue_ready));这个位置了 不知道是什么原因,感谢指点
[ 本帖最后由 liujq110 于 2009-4-9 18:03 编辑 ] |
|