当前位置: 技术问答>linux和unix
线程终止问题
来源: 互联网 发布时间:2017-03-25
本文导语: #include #include #include #include #include void pthreadcancel(void* thread) { printf("%s stop caused by signal.n",(char*)thread); } void* thread1(void*arg) { int oldstate, oldstyle; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&oldstate); pthread_setcanceltype(PTHREAD_CANC...
#include
#include
#include
#include
#include
void pthreadcancel(void* thread)
{
printf("%s stop caused by signal.n",(char*)thread);
}
void* thread1(void*arg)
{
int oldstate, oldstyle;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&oldstate);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldstyle);
pthread_cleanup_push(pthreadcancel,(void*)"Thread1");
int i;
int *times = (int *)arg;
for(i = 0; i