C++ 增强线程池
我试图用boostthreadpool库创建一个threadpool,但是在定义它时,我不断地发现很多关于模板参数错误的错误 我可能做了一些根本错误的事情,但我没有看到C++ 增强线程池,c++,boost,threadpool,C++,Boost,Threadpool,我试图用boostthreadpool库创建一个threadpool,但是在定义它时,我不断地发现很多关于模板参数错误的错误 我可能做了一些根本错误的事情,但我没有看到 //Threadpool typedef boost::threadpool::thread_pool< boost::threadpool::task_func, boost::threadpool::fifo_scheduler<tsk>, boost::threadpool::st
//Threadpool
typedef boost::threadpool::thread_pool<
boost::threadpool::task_func,
boost::threadpool::fifo_scheduler<tsk>,
boost::threadpool::static_size<boost::threadpool::fifo_pool>,
boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
> pool;
//线程池
typedef boost::线程池::线程池<
boost::threadpool::task_func,
boost::threadpool::fifo_调度程序,
boost::threadpool::静态大小,
boost::threadpool::调整_控制器的大小,
boost::threadpool::等待\u活动\u任务
>水池;
错误:
------ Build started: Project: Trial, Configuration: Debug Win32 ------
Compiling...
Trial.cpp
error C2923: 'boost::threadpool::fifo_scheduler' : 'tsk' is invalid as template argument '#1', type expected
see declaration of 'tsk'
error C3200: 'boost::threadpool::fifo_pool' : invalid template argument for template parameter 'SizePolicy', expected a class template
error C3200: 'boost::threadpool::resize_controller<Pool>' : invalid template argument for template parameter 'SizePolicyController', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
error C3200: 'boost::threadpool::wait_for_active_tasks<Pool>' : invalid template argument for template parameter 'ShutdownPolicy', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
error C3200: 'boost::threadpool::fifo_pool' : invalid template argument for template parameter 'SizePolicy', expected a class template
see reference to class template instantiation 'boost::threadpool::thread_pool<Task,SchedulingPolicy,SizePolicy,SizePolicyController,ShutdownPolicy>' being compiled
with
[
Task=boost::threadpool::task_func,
SchedulingPolicy=boost::threadpool::fifo_scheduler,
SizePolicy=boost::threadpool::fifo_pool,
SizePolicyController=boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
ShutdownPolicy=boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(79) : error C3200: 'boost::threadpool::resize_controller<Pool>' : invalid template argument for template parameter 'SizePolicyController', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(79) : error C3200: 'boost::threadpool::wait_for_active_tasks<Pool>' : invalid template argument for template parameter 'ShutdownPolicy', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(91) : error C2059: syntax error : '<'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(91) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(92) : error C2059: syntax error : '<'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(92) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(111) : error C2146: syntax error : missing ';' before identifier 'size_controller'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(111) : error C2501: 'boost::threadpool::thread_pool<Task,SchedulingPolicy,SizePolicy,SizePolicyController,ShutdownPolicy>::size_controller_type' : missing storage-class or type specifiers
with
[
Task=boost::threadpool::task_func,
SchedulingPolicy=boost::threadpool::fifo_scheduler,
SizePolicy=boost::threadpool::fifo_pool,
SizePolicyController=boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
ShutdownPolicy=boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(112) : warning C4183: 'size_controller': missing return type; assumed to be a member function returning 'int'
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
----构建已启动:项目:试用,配置:调试Win32------
编译。。。
Trial.cpp
错误C2923:“boost::threadpool::fifo_调度程序”:“tsk”作为模板参数“#1”无效,应为类型
见“tsk”声明
错误C3200:“boost::threadpool::fifo_pool”:模板参数“SizePolicy”的模板参数无效,应为类模板
错误C3200:“boost::threadpool::resize_controller”:模板参数“SizePolicyController”的模板参数无效,应为类模板
具有
[
池=boost::线程池::先进先出池
]
错误C3200:“boost::threadpool::wait_for_active_任务”:模板参数“ShutdownPolicy”的模板参数无效,应为类模板
具有
[
池=boost::线程池::先进先出池
]
错误C3200:“boost::threadpool::fifo_pool”:模板参数“SizePolicy”的模板参数无效,应为类模板
请参阅正在编译的类模板实例化“boost::threadpool::thread\u pool”的参考
具有
[
Task=boost::threadpool::Task_func,
SchedulingPolicy=boost::threadpool::fifo_调度程序,
SizePolicy=boost::threadpool::fifo_池,
SizePolicyController=boost::threadpool::resize\u控制器,
ShutdownPolicy=boost::threadpool::等待\u活动\u任务
]
c:\Program Files\boost\boost\u 1\u 44\boost\threadpool\pool.hpp(79):错误C3200:“boost::threadpool::resize\u controller”:模板参数“SizePolicyController”的模板参数无效,应为类模板
具有
[
池=boost::线程池::先进先出池
]
c:\Program Files\boost\boost\u 1\u 44\boost\threadpool\pool.hpp(79):错误C3200:'boost::threadpool::wait_for_active_tasks':模板参数'ShutdownPolicy'的模板参数无效,应为类模板
具有
[
池=boost::线程池::先进先出池
]
c:\ProgramFiles\boost\boost\u 1\u 44\boost\threadpool\pool.hpp(91):错误C2059:语法错误:“根据您的评论,tsk
是一个变量。不能将运行时表达式(如变量)作为模板参数传递。模板完全是编译时的
对于此特定问题,您只需执行以下操作:
typedef boost::threadpool::thread_pool<> pool;
void taskfunc();
// later on...
pool my_pool;
my_pool.schedule(&taskfunc);
typedef boost::threadpool::thread_pool;
void taskfunc();
//后来。。。
池我的池;
我的池计划(&taskfunc);
boost::threadpool::task_func
只是一个boost::function0
-任何0-arg void函数指针都可以转换为该类型。根据您的评论,tsk
是一个变量。不能将运行时表达式(如变量)作为模板参数传递。模板完全是编译时的
对于此特定问题,您只需执行以下操作:
typedef boost::threadpool::thread_pool<> pool;
void taskfunc();
// later on...
pool my_pool;
my_pool.schedule(&taskfunc);
typedef boost::threadpool::thread_pool;
void taskfunc();
//后来。。。
池我的池;
我的池计划(&taskfunc);
boost::threadpool::task_func
只是一个boost::function0
-任何0-arg void函数指针都可以转换为该类型。“关于模板参数出错的大量错误”根本不是描述性的。tsk的声明是什么样子的?void taskfunc();boost::threadpool::task_func tsk=taskfunc//任务“关于模板参数错误的大量错误”根本不是描述性的。tsk的声明是什么样子的?void taskfunc();boost::threadpool::task_func tsk=taskfunc//任务