文章目录
欢迎访问个人网络日志🌹🌹知行空间🌹🌹
线程闩std::latch和线程卡std::barrier
线程闩std::latch
线程闩std::latch是c++20中引入的类,是为了计数std::ptrdiff_t类型的变量。
std::latch中使用的计数器在创建时初始化,线程工作过程中逐渐减少变量的值,直到为零。
std::latch对象中的值不支持重置或修改。
#include <thread>
#include <latch>
#include <vector>
#include <future>
struct my_data
{
int x;
int y;
};
my_data make_data(int i){
return {
i, i+1}; }
void do_more_stuff() {
}
void process_data(my_data &data, unsigned count)
{
}
void foo(){
unsigned const thread_count=10;
std::experimental::latch done

最低0.47元/天 解锁文章
906

被折叠的 条评论
为什么被折叠?



