首页 > 解决方案 > 如何在 cpp 的线程中使用 = 运算符,它有什么好处?

问题描述

std::thread([=]{

//my statements and my other stuff, basically here i am updating the database accordingly some conditions.

  }).detach();

那么,它的用途、好处或如何使用它:std::thread([=]

标签: c++multithreadingc++11

解决方案


在此代码中,您使用 lambda 作为 std::thread 函数。[=] 是一个捕获子句,表示按值捕获所有外部变量

auto lambdaExample = [](){ std::cout << "HELLO WORLD\n"; };

推荐阅读