int pthread_equal (pthread_t th1,pthread_t th2);p thread_equal function Compare Th1 to Th2 is the same thread, because the pthread_t data type is not considered an integer because it can not be said, So it is not possible to compare pthread_t in a way that compares integers. If Th1 is the same as Th2, the function returns a value other than 0 if different functions return 0.
Thread Properties -- The attr parameter that was previously called Pthread_create passed in is a null pointer, not a pointer to the pthread_attr_t structure-- you can use Pthread_attr_ The t structure modifies the default properties of the thread and links these properties to the created thread. -- You can use the Pthread_attr_init function to initialize the pthread_attr_t structure. --After calling Pthread_attr_init, the structure of the pthread_attr_t contains the default values that the operating system implements to support all properties of the thread. If you want to modify the values of individual properties, you need to call other functions.
int Pthread_attr_destroy (pthread_attr_t *attr); int pthread_attr_init (pthread_attr_t *attr); function Pthread_attr_init initializes the attr structure. The structure of the function Pthread_attr_destroy frees the attr memory space pthread_attr_t is opaque to the application, and the application does not need to understand the internal composition of the structure. Previously introduced the concept of the Pthread_detach function, you can specify the thread's properties as detach by pthread_attr_t when creating the thread, instead of having to modify the thread properties later. int pthread_attr_setdetachstate (pthread_attr_t *attr,iny detachstate); function pthread_attr_ Setdetachstate set the Thread property to one of the following two valid values --pthread_create_detached sets the thread to the detached state --pthread_create_joinable set thread to normal state
//the use of the second parameter of the Pthread_create () function#include <stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<errno.h>#include<pthread.h>void* MYFUNC (void*Arg) { while(1) {printf ("Fly the air\n"); Sleep (1); } returnNULL;}intMainintArgChar*args[]) {pthread_t thr1; pthread_attr_t attr; Pthread_attr_init (&attr); //to set a process as separablePthread_attr_setdetachstate (&attr,pthread_create_detached); //Creating Threads if(Pthread_create (&thr1,&attr,myfunc,null)! =0) {printf ("Create thread is failed! Error message:%s\n", Strerror (errno)); return-1; } //releasing a Process Property objectPthread_attr_destroy (&attr); /*disconnected threads cannot be accepted with the Pthread_join () function*/Pthread_join (thr1,null);//Invalid callSleep2); printf ("Main end\n"); return 0;}
LInux process and Thread Cheng