C++中,为什么执行pthread_mutex_lock()时执行了两次线程才被阻塞?
狂烂球 2005-11-30 04:52:13 在线程函数里,
执行了两次pthread_mutex_lock,线程才被阻塞,请问是什么原因?
pthread_mutex_init(&mutex,NULL);
void *threadfunc()
{
......
while(1)
{
pthread_mutex_lock(&mutex);
......
}
}
int main()
{
pthread_create();
......
pthread_mutex_unlock(&mutex);
}
在这里,执行了两次才被阻塞,请问是什么原因呢?