1. 在lock与unlock之间,调用pthread_exit 或者在线程外部调用pthread_cancel
其他线程被永久死锁
例子:
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
pthread_mutex_tm;
void * runodd(void* d)
{
int i=0;
for(i=1;;i+=2)
{
pthread_mutex_lock(&m);
printf(“%d\n”,i);
if(i>100000)
{
pthread_exit(0);
}
pthread_mutex_unlock(&m);
}
void * runeven(void*d)
{
int i=0;
for(i=0;;i+=2)
{
pthread_mutex_lock(&m);
printf(“%d\n”,i);
pthread_mutex_unlock(&m);
}
}
void main()
{
pthread_t todd,tevent;
pthread