取消线程,是否会释放线程的所有资源?

#include 
#include 
#include 
#include 
//取消线程,是否会释放线程的所有资源?例子:
void *thread1(void *arg)
{
        printf("start thread (%u)\n", (unsigned)pthread_self());
}       
int main(int argc, char *argv[])
 {       
        pthread_t  t1, t2, t3;
         int ret;
       printf("main start\n");
        do{     
                ret = pthread_create(&t1, NULL, thread1, NULL);
                if(ret != 0)
                 {       
                        printf("create thread failed\n");
                        exit(1);
                }
                pthread_cancel(t1);
                printf("<<<<<<");//much too importent这行代码很重要
             
                //pthread_join(t1, NULL);这句加上,将不断创建新线程.
                if(ret != 0)
                {       
                        printf("join failed\n");
                        exit(1);
                }
        }while(1);
     return 0;
 }   
//运行结果:
/*start thread (349191056), 327
start th<<<<<<<<<<<<<<<<<<<<<<*/
//注意:取消线程相当于使用pthread_exit终止线程。

 

你可能感兴趣的:(取消线程,是否会释放线程的所有资源?)