C++多线程6
2021/11/21 20:12:32
本文主要是介绍C++多线程6,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
这里,只是记录自己的学习笔记。
顺便和大家分享多线程的基础知识。然后从入门到实战。有代码。
知识点来源:
https://edu.51cto.com/course/26869.html
lambda临时函数作为线程入口函数
1 #include <iostream> 2 #include <string> 3 #include <thread> 4 5 using namespace std; 6 7 //lambda临时函数作为线程入口函数 8 9 10 //线程入口为类成员 lambda 函数 11 class TestLambda{ 12 public: 13 void Start() { 14 thread th([this]() {cout << "name= " << name<< endl; }); 15 th.detach(); 16 } 17 18 string name = "test lambda"; 19 }; 20 21 int main() { 22 23 // 用 lambda 表达式作为线程入口函数,并接收一个参数 24 thread th( 25 [](int i) { 26 cout << "lambda i:" << i << endl; 27 }, 666); 28 th.join(); 29 30 31 TestLambda test; 32 test.Start(); 33 34 35 36 getchar(); 37 return 0; 38 }
这篇关于C++多线程6的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28pyqt 怎么打包整个项目-icode9专业技术文章分享
- 2024-09-28laravel Commands 创建带有参数的 Artisan 命令的步骤和示例-icode9专业技术文章分享
- 2024-09-28antd怎么实现渲染tiff图片-icode9专业技术文章分享
- 2024-09-28英文半角中划线和中文全角的中划线有什么区别-icode9专业技术文章分享
- 2024-09-28nvm npm 和node 他们之间有什么关系-icode9专业技术文章分享
- 2024-09-28Node Version Manager (nvm)使用教程-icode9专业技术文章分享
- 2024-09-28nvm命令太慢,是什么原因-icode9专业技术文章分享
- 2024-09-28Kotlin 如何增加、删除和修改 MutableStateFlow 中的值。-icode9专业技术文章分享
- 2024-09-28Kotlin的stateFlow.update 写法介绍-icode9专业技术文章分享
- 2024-09-28kotlin 怎么获取当前时间格式-icode9专业技术文章分享