Lambda函数作为线程入口
#include <thread>
#include <iostream>
#include <string>
//Linux -lpthread
using namespace std;
// 测试带有 lambda 的线程
class TestLambda
{
public:
void Start()
{
thread th([this]() {cout << "name = " << name << endl; });
th.join();
}
string name = "test lambda";
};
int main(int argc, char* argv[])
{
// lambda 作为临时函数.
thread th(
[](int i) {cout << "test lmbda " << i << endl; },
123
);
th.join();
TestLambda test;
test.Start();
return 0;
}