[Linux-C] thread

Source: Internet
Author: User

# Include <pthread. h>

Int pthread_create (

Pthread_t * thread,

Pthread_attr_t * attr,

Void * (* start_routine) (void *),

Void * arg

);

 

 

Void pthread_exit (void * retval );

 

Int pthread_join (pthread * thread, void ** thread_return );

 

Pthread_create creates a thread,

Thread is used to indicate the ID of the thread to be created,

Attr indicates the attributes when a thread is created. We use NULL to indicate that the default attribute is used.

Start_routine function pointer is the function that starts to be executed after the thread is created successfully,

Arg is the only parameter of this function. It indicates the parameter passed to start_routine.

 

The pthread_exit function is similar to the exit function to exit a thread. this function ends the thread, releases the function resource, and blocks it until other threads use the pthread_join function to wait for it. then pass the * retval value to ** thread_return.

 

Because this function releases function resources, retval cannot point to the local variables of the function.

 

Pthread_join is the same as wait call to wait for the specified thread.

 

Pthread_exit is called when start_routine exits;

Pthread_join is called outside the thread to receive the content returned by the thread.

Related Article

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.