gpt4 book ai didi

c++ - 多线程执行的输出只发生一次?

转载 作者:行者123 更新时间:2023-11-30 03:22:56 27 4
gpt4 key购买 nike

<分区>

#include <iostream>
#include <thread>

void func() {
std::cout << "Hello";
}

int main() {
std::vector<std::thread> threads;
int n = 100;
for (int i = 0; i < n; i++) {
std::cout << "executing thread" << std::endl;
threads.push_back(std::thread(func));
}
}

我的程序打印一次“executing thread”然后结束。这是什么原因?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com