Multithreading
#include <iostream>#include<pthread.h>//multi-Threaded related operation header file, portable many platformsusing namespacestd;#defineNum_threads 5//Number of Threadsvoid* Say_hello (void*args) {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, run functionThe Parametersif(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}
Compiling g++-o udpbench udpbench.cpp-lpthread
Run./udpbench
The first C + + program after work