线程:CPP lambda表达式与多线程

来源:互联网 发布:江铃顺达仪表算法 编辑:程序博客网 时间:2024/05/29 18:26
c++ lambda表达式获取线程ID以及线程等待
#include <thread>#include<chrono>
thread th1([](){this_thread::sleep_for(chrono::seconds(3));cout << this_thread::get_id() << endl;});thread th2([](){this_thread::sleep_for(chrono::seconds(5));cout << this_thread::get_id() << endl;});

thread th3([](){this_thread::sleep_for(chrono::seconds(3));//等待3秒  显示IDthis_thread::yield();//让CPU先执行其他线程  空闲时再执行自己cout << this_thread::get_id() << endl;//this_thread::sleep_until();//sleep_until  一直等待到某一时刻});thread th4([](){this_thread::sleep_for(chrono::seconds(5));//等待5秒  显示线程IDcout << this_thread::get_id() << endl;});




0 0
原创粉丝点击