Re: [Cppcms-users] thread_pool questions
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-05-03 11:01:58
|
----- Original Message ----- > > Hi everyone, > Hi, > my last idea was to extend the thread pool and have some questions about it. > > As far as I know, async methods should not run too long, because they > block the entire service loop, right?! > Exactly > Also i have some other questions: > > At first: Could i "avoid" the thread pool and create a std::thread > instead? (Maybe i can give the thread pool a reference the thread object) > Of course you can. But: 1. Creation of a new thread is heavy procedure, it is much better and faster to submit a job to a pool 2. If you create too many threads it may cost a lot, thread pool would just enqueue the job that would be executed at some point, of the pool is too busy. 3. The size of the CppCMS's thread pool is optimized for run-time hardware concurrency So it is your choice :-) > Second: Would it be possible to give a std::function object to the > thread_pool? Yes, http://cppcms.com/cppcms_ref/latest/classcppcms_1_1thread__pool.html thread_pool::post receives a booster::function - the template object that can be created from any function-like object, including std::function. > > Third: What about callbacks? If a thread is finished you could define a > callback where you can define further operations (like evaluating the > result of the thread) > When the result of the thread is ready, post a job (some other callback) to the event loop using booster::aio::io_service::post. It would allow you to handle completion of the job in the pool. This post method receives generic callback as well. > Regards > > Marcel > Best, Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ |