Linux pthread pthread_create pthread_join Pthread_detach

Source: Internet
Author: User

Linux The default pthread_create is owned by the caller responsible for the resource recycling of the child thread

When the parent thread exits, the child thread also exits, so the parent thread is pushed out to call the Pthread_join function to block waiting for the child thread to exit

Pthread_detach (TID) keeps thread Tid's thread in a detached state, the thread is in a detached state, the resource is reclaimed when the thread terminates, otherwise the terminating child thread consumes system resources until the parent thread calls Pthread_join

1 Parent line enters upgradeable and child thread termination

At this time

If a child thread is nearly detached from the parent thread, such as calling Pthread_datach, the resource is recycled

If there is no separation, the resource cannot be freed

1 Sub-line enters upgradeable with parent thread termination

At this time

If a child thread calls a thread-detach function Pthread_detach, or the parent thread calls the Pthread_join, the resource is freed

Resource cannot be freed if none of the above two are called

Linux pthread pthread_create pthread_join Pthread_detach

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.