Linux Thread Recycling __linux

Source: Internet
Author: User
int Pthread_create (pthread_t *thread, const pthread_attr_t *attr,
                   void * (*start_routine) (void *), void *arg);

void Pthread_exit (void *retval);

1. Set Thread Properties
If the Attr property is set to NULL when the thread is created, the thread takes the default property joinable. You need to set the property to detached

int Pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate);
int Pthread_attr_getdetachstate (pthread_attr_t *attr, int *detachstate);

pthread_t thread_id;
pthread_attr_t attr;
Pthread_attr_init (&attr);
Pthread_attr_setdetachstate (&attr, pthread_create_detached);
Pthread_create (&thread_id, &attr, Func, NULL);
Pthread_attr_destroy (&ATTR);

2. Pthread_join
Block wait thread exit and cleanup (similar to waiting, Waitpid)

int Pthread_join (pthread_t thread, void **retval);

Pthread_join (thread, (void**) &thread_ret); The parent thread invokes
printf ("Thread_ret =%d.\n", *thread_ret);

3. Pthread_detach Non-blocking

int Pthread_detach (pthread_t thread);

Pthread_detach (Pthread_self ()); Child thread Call

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.