📜  传递对线程 c++ 的引用 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:41.384000             🧑  作者: Mango

代码示例1
void foo(int& b)
{
    b = 10;
}

int a = 1;
std::thread thread{ foo, std::ref(a) }; //'a' is now really passed as reference

thread.join();
std::cout << a << '\n'; //Outputs 10