http://blog.csdn.net/hitwengqi/article/details/8015646
- Basic Usage
#include <iostream>#include<pthread.h>using namespacestd;#defineNum_threads 5void* Say_hello (void*args) {Sleep (Ten); cout<<"Hello ..."<<Endl;} //function Returns a function pointer, which is easy to follow as a parameterintMain () {pthread_t tids[num_threads];//Thread ID for(intI=0; i < num_threads; ++i) {intret = Pthread_create (&tids[i], NULL, Say_hello, NULL);//parameters: Create thread ID, thread parameter, start address of thread run function, parameters of run function if(Ret! =0)//Create line Cheng return 0{cout<<"pthread_create Error:error_code"<< ret <<Endl; }} pthread_exit (NULL); //wait for each thread to exit before the process ends, or the process forces the end and the thread is in an unterminated state}/*vim:set ts=4 sw=4 sts=4 tw=100*/
g++-O muti_thread_test_1 muti_thread_test_1.cpp-lpthread
C + + multithreaded programming