0
我找到了一個線程池類,我嘗試了很多組合來調用裏面的函數。把功能放到模板中
這裏是比如我試試:
WorkerPool wp(4);
wp.run_task<Connection::On_NET1_LOGIN>(&On_NET1_LOGIN());
這裏是工作者池的功能:
template < typename Task >
void run_task(Task task)
{
boost::unique_lock<boost::mutex> lock(mutex_);
// If no threads are available, then return.
if (0 == available_) return;
// Decrement count, indicating thread is no longer available.
--available_;
// Post a wrapped task into the queue.
io_service_.post(boost::bind(&WorkerPool::wrap_task, this,
boost::function< void() >(task)));
}
private:
/// @brief Wrap a task so that the available count can be increased once
/// the user provided task has completed.
void wrap_task(boost::function< void() > task)
{
// Run the user supplied task.
try
{
task();
}
// Suppress all exceptions.
catch (...) {}
// Task has finished, so increment count of available threads.
boost::unique_lock<boost::mutex> lock(mutex_);
++available_;
}
我做錯了什麼在調用函數到線程池? 謝謝。
什麼是錯誤信息? – MSalters