参考https://www.cnblogs.com/a3192048/p/12241309.html
调试通过,实例如下:
g++ -pthread x.cpp -o m
x.cpp:
#include <iostream>
#include <cstdlib>
#include <pthread.h>
using namespace std;
//#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
int tid = *((int*)threadid);
cout << "接收到参数: " << tid << endl;
pthread_exit(NULL);
}
int main ()
{
pthread_t xc1;
int mm=123;
pthread_create(&xc1, NULL, PrintHello, (void *)&(mm));
pthread_exit(NULL);
}
本实例,将参数mm传入子线程。