linux environment programming-thread related functions

Earlier, I introduced in detail the difference between threads and processes [under linux], and the concept of threads. Now let's introduce the control statement of the thread (human words are the function of operating the thread)

1. The pthread_self function gets the thread ID. Its role corresponds to the getpid() function in the process.
pthread_ t pthread self(void);
Return value: success: 0;
failure: none!
Thread ID: pthread t type, essence: unsigned integer (%lu) under Linux, other systems may be a structure to achieve
thread ID It is the internal identification mark of the process. (The thread ID is allowed to be the same between the two processes)
Note: The global variable pthread _t tid should not be used, and the thread ID should be obtained through the pthread_ create outgoing parameter in the child thread, but pthread_ self should be used.
 

2. The pthread_ create function creates a new thread.
Its role corresponds to the fork) function in the process.
int pthread create(pthread _t *thread, const pthread attr _t *attr, void *(*start_ routine) (void *), void * arg);
Return value: success: 0;
failure: error number---inux environment , All thread characteristics, failure will directly return the error number.
Parameter:
pthread t: current Linux can be understood as: typedef unsigned long int pthread _t;
Parameter 1: outgoing parameter, save the thread ID assigned to us by the system.
Parameter 2: usually pass NULL, which means using thread default attributes. If you want to use specific attributes, you can also modify this parameter.
Parameter 3: Function pointer ࿰

Guess you like

Origin blog.csdn.net/qq_44065088/article/details/109155127