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: