#include <stdlib.h>#include<pthread.h>#include<stdio.h>#include<sched.h>//cancels the thread, does it release all resources for the thread? Example:void*thread1 (void*Arg) {printf ("start thread (%u) \ n", (unsigned) pthread_self ());} intMainintargcChar*argv[]) {pthread_t T1, T2, T3; intret; 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 this line of code is important.//pthread_join (t1, NULL); In addition, new threads are created continuously. if(Ret! =0) {printf ("Join failed\n"); Exit (1); } } while(1); return 0; } //Operation Result:/*start Thread (349191056), 327start th<<<<<<<<<<<<<<<<<< <<<<<create thread failed Note: Each run of the results are different, in the main thread added printf to limit the speed of the thread, but can generate a number of threads are around 350, should be able to judge, Canceling does not completely release resources. So after you cancel the thread, you should also use join to completely release the resource.*///Note: Canceling a thread is equivalent to terminating the thread with Pthread_exit.
Cancels the thread, does it release all resources for the thread?