#include <iostream>#include<pthread.h>//multi-Threaded related operation header file, portable many platformsusing namespacestd;structmypara{intPARA1;//parameter 1 Char*para2;//Parameter 2pthread_t wait;};void* THREAD1 (void* args)//This function demonstrates that the data is outgoing{Mypara*my = (Mypara *) args; Srand (Unsigned (0))); My->PARA1 = rand ()% -; My->para2 =". "; cout<<"end of assignment to struct"<<Endl; return 0;} void* THREAD2 (void* args)//This function demonstrates that the data is passed in{Mypara*str_in = (Mypara *) args; cout<<"Thread 2 starts to run ........ ........."<<Endl; Pthread_join (str_in->wait,null);//You need to wait for the thread1 thread to finish assigning the struct struct to runcout <<"the random number generated by thread 1 is:"<< str_in->para1<<" "<< Str_in->para2 <<Endl; return 0;} intMain () {pthread_t tid1,tid2; Mypara My_para; intret = Pthread_create (&TID1, NULL, Thread1, (void*) &My_para); //Pthread_join (tid1,null);My_para.wait =Tid1; Pthread_create (&tid2, NULL, Thread2, (void*) &My_para); System ("Pause"); Pthread_exit (NULL); }
C + + Multithreading parameter Transfer-pass the parameters through the struct. (Pthread multi-threaded class library, cannot compile on x64 bit)
The delivery of C + + multithreading parameters