1 Thread-to-process comparison
Here is a detailed description of the notes
http://blog.csdn.net/laviolette/article/details/51506953
2 Creating a thread function
int Pthread_create (pthread_t *thread, const pthread_attr_t *attr,
void * (*start_routine) (void *), void *arg);
Parameter meaning:
typedef unsigned LONG int pthread_t
(1) pthread_t *thread: storage thread ID Unique
(2) const pthread_attr_t *ATTR: Thread property setting is typically null for stack-related properties
(3) void * (*start_routine) (void *): function pointer specifies which function code to run
(4) void *arg: The parameter address of the running function is usually passed to the parameter of the custom function
Example: Creating a new thread and passing multiple parameters using a struct note that when compiling, add-lpthread
1#include <pthread.h>2#include <stdio.h>3#include <stdlib.h>4#include <string.h>5 6 structStudent7 {8 intAge ;9 Char*name;Ten }; One A void*print (structStudent *str) - { -printf"The age is %d\n",str->Age ); theprintf"The name is%s\n",str->name); - } - - intMain () + { - structstudent Stu; + pthread_t thread_id; AStu.age = -; atStu.name ="GoGoGo"; -Pthread_create (&thread_id,null, (void*) *print,&stu);//Creating Threads -printf"The new thread ID is%u\n", thread_id); -Pthread_join (Thread_id,null);//wait for the child thread to end in the main thread - return 1; -}
Added: int pthread_join (pthread_t thread, void **retval), thread wait function
Linux thread note 1 creation thread