POSIX thread Programming (ii) thread creation and termination

Source: Internet
Author: User
Tags posix thread

Creating and terminating Threads

The common APIs for threading management are:

Pthread_create (Thread,attr,start_routine,arg)
pthread_exit (status)
pthread_cancel (thread)
Pthread_ Attr_init (attr)
Pthread_attr_destroy (attr)

To create a thread:

A main program contains a default main thread that is created by the system when the program starts running. All other threads must be explicitly created by the programmer.

Pthread_create to create an executable thread. Create a thread each time you call, and you can call the function in any location.

Pthread_create Parameters:

Thread: An identifier that uniquely identifies a new thread that is not visible to the user, generated by pthread_create

attr: An invisible Property object of a thread that can be used to set the properties of a new thread. You can pass in a thread Property object, type pthread_attr_t, or null to use the default value.

Start_routine: A subroutine that is executed immediately by a new thread when a new thread is created

ARG: A parameter passed to Start_routine. It must be a pointer of type void, with no parameters or default to pass NULL. If you want to pass in multiple parameters, you can encapsulate them into a struct.

The maximum number of threads that a process can create has different implementations within different systems.

The number of threads in the Linux query and set your system is limited by the following methods:

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.