gpt4 book ai didi

C++ cppreference.com 在谈论哪个线程池?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:41:36 32 4
gpt4 key购买 nike

我在 cppreference.com 上阅读了 std::async 的描述。第一个描述说:

The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.

. [cppreference 链接]:std::async

cppreference.com 所说的线程池是什么?

我阅读了标准草案 N4713 (C++ 17),其中没有提及可能的线程池用法。我也知道目前标准 C++ 中没有线程池。

最佳答案

cppreference 和 C++ 标准实际上在这一点上存在分歧。 cppreference 是这样说的(我的强调和删除线):

The template function async runs the function f asynchronously ( potentially optionally in a separate thread which may be part of a thread pool).

C++ standard是这样说的:

If launch::async is set in policy, [std::async] calls [the function f] as if in a new thread of execution ...

这显然是两个不同的东西。

只有 Windows 的 std::async 实现使用线程池 AFAIK,而 gcc 和 clang 为每次调用 std::async 启动一个新线程(当launch::asyncpolicy中设置),因此遵循标准。

更多分析在这里:https://stackoverflow.com/a/50898570/5743288

关于C++ cppreference.com 在谈论哪个线程池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55873027/

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