d[1], NULL, thread1, NULL);
sleep(1);
pthread_cancel(tid[0]);
printf("main thread request cancel thread 0\n");
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_cond_destroy(&cond);
pthread_mutex_destroy(&mutex);
return 0;
}
最后,引用一篇由pthread_cancel引起死锁的博客https://blog.csdn.net/xsckernel/article/details/48052425,提取核心内容如下:
“通常的说法:某某函数是Cancellation Points,这种方法是容易令人混淆的。因为函数的执行是一个时间过程,而不是一个时间点。其实真正的Cancellation Points 只是在这些函数中Cancellation Type被修改为PHREAD_CANCEL_ASYNCHRONOUS和修改回PTHREAD_CANCEL_DEFERRED中间的一段时间。”
|