【发布时间】:2019-02-18 19:00:32
【问题描述】:
我正在尝试实现我自己的并行版本,以使用 https://github.com/Fdhvdu/ThreadPool 作为后端线程池
我将任务分成几个部分并启动一个具有以下功能的线程:
template <typename Callable>
void launchRange(int id, Callable func, int k1, int k2)
{
for (int k = k1; k < k2; k++) {
func(k);
}
}
我遇到的问题是如何将这个Callable 传递给线程池
相关部分是:
poolPtr->add(launchRange, func, i1, i2);
但我不断收到编译错误。错误是:
...\ithreadpoolitembase.hpp(36): error C2027: use of undefined type 'std::tuple<conditional<_Test,void(__cdecl *&)(int),_Ty>::type,conditional<_Test,int&,int>::type,conditional<_Test,int&,int>::type>'
with
[
_Ty=void (__cdecl *)(int)
]
add的接口是
template<class Func,class ... Args>
inline thread_id add(Func &&func,Args &&...args);
我正在使用 Visual Studio 2017 Community 15.4 和 /std:c++17
【问题讨论】:
-
问题中有
c++11标签,但你使用/std:c++17?由于您使用的是VS2017,您是否尝试过使用Execution policies的函数? -
c++17评论是因为链接的 ThreadPool 库声明它需要 c++17,所以我想避免 cmets 声明 VS2017 15.4 不完全支持 c++17。跨度>
标签: c++ multithreading c++11 threadpool