Cancels the thread, does it release all resources for the thread?

Source: Internet
Author: User

#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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.