c++ - 如何在 cpp 的线程中使用 = 运算符,它有什么好处?
问题描述
std::thread([=]{
//my statements and my other stuff, basically here i am updating the database accordingly some conditions.
}).detach();
那么,它的用途、好处或如何使用它:std::thread([=]
解决方案
在此代码中,您使用 lambda 作为 std::thread 函数。[=] 是一个捕获子句,表示按值捕获所有外部变量
auto lambdaExample = [](){ std::cout << "HELLO WORLD\n"; };
推荐阅读
- php - 每分钟运行的 Laravel cron 作业使 mysql 连接数翻倍
- ios - 自定义导航控制器适用于 iOS 13 但不适用于 iOS 12
- mysql - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 解决方法不工作
- .net - 什么决定了 ngen 查找的程序集标识?
- sql - 如何通过在“返回视图方法”中传递计数值来显示表中包含的记录总数(计数)
- c++ - 如何使用QtCreator而不是gdb来调试基于Rcpp的R包中的C++代码
- java - 下载带有 HttpURLConnection 问题的 *.deb 文件
- db2 - db2 rollforward 命令输出在非目录分区的“处理的日志文件”列中显示“-”
- java - RXJava Retrofit 返回 POST HTTP 错误 500
- java - 尝试在空对象引用上调用虚拟方法“android.widget.Filter com.app.app.adapter.TextTypingCustomAdapter.getFilter()”