【发布时间】:2020-09-25 01:08:47
【问题描述】:
使用 std #include 如果我想让线程运行它,我将如何返回一个值?
例如
include <iostream>
#include <thread>
usingnamespace std;
int func(int a)
{
int b = a*a
return b;
}
int main()
{
thread t(func);
t.join();
return 0;
}
如何修改
thread t(func);
这样我就可以得到b
【问题讨论】:
-
您可以改用
std::async。 -
对于 std::async 看看davidespataro.it/cpp-concurrency-threads-future
-
是的,尽管我真的很喜欢异步,但我的书说我需要使用 std::thread
标签: c++ multithreading