pthread_cond_wait 不阻塞?
请教为什么下面的程序,在pthread_cond_wait这不阻塞呢。
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include<errno.h>
// 读写互斥体
pthread_mutex_t mutexWriteRead = PTHREAD_MUTEX_INITIALIZER;
// 读条件变量
pthread_cond_t condWrote = PTHREAD_COND_INITIALIZER;
int main(int args, const char *argc[])
{
// 如果 要写位置是待读位置 的话,则
int dwRet =0;
do
{
pthread_mutex_lock( &mutexWriteRead );
dwRet=pthread_cond_wait(&condWrote, &mutexWriteRead ); //应当阻塞在此,但没有
if( EINVAL == dwRet )
{
printf("== EINVAL\n");
}
else
{
printf("end wait %d\n",dwRet);
}
}
while(1);
}
在ubuntu上运行此程序,结果如下:pthread_cond_waint根本没有阻塞,它的返回值为0说明它是接收到了信号,但这个信号从什么地方来的呢。
end wait 0
end wait 0
end wait 0
end wait 0
...