1.全局函数作为传参入口
#include <iostream>
#include <thread>
#include <string>
void ThreadMain(int p1,float p2,std::string str)
{
std::cout << "p1:" << p1 << std::endl;
std::cout << "p2:" << p2 << std::endl;
std::cout << "str:" << str << std::endl;
}
int main()
{
std::thread th;
{
float f = 12.1f;
th = std::thread(ThreadMain, 101, f, "test_str");
}
th.join();
return 0;
}
2.传递指针
①传递空间已经销毁
②多线程共享访问一块空间
③传递的指针变量的生命周期小于线程