Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ctpl.h
Go to the documentation of this file.
53 thread_pool(int nThreads, int queueSize = _ctplThreadPoolLength_) : q(queueSize) { this->init(); this->resize(nThreads); }
68 // should be called from one thread, otherwise be careful to not interleave, also with this->stop()
93 this->flags.resize(nThreads); // safe to delete because the threads have copies of shared_ptr of the flags, not originals
109 std::unique_ptr<std::function<void(int id)>> func(_f); // at return, delete the function even if an exception occurred
120 // if isWait == true, all the functions in the queue are run, otherwise the queue is cleared without running the functions
140 for (int i = 0; i < static_cast<int>(this->threads.size()); ++i) { // wait for the computing threads to finish
144 // if there were no threads in the pool but some functors in the queue, the functors are not deleted by the threads
168 // run the user's function that excepts argument int - id of the running thread. returned value is templatized
169 // operator returns std::future, where the user can get the result and rethrow the catched exceptins
195 std::shared_ptr<std::atomic<bool>> flag(this->flags[i]); // a copy of the shared ptr to the flag
202 std::unique_ptr<std::function<void(int id)>> func(_f); // at return, delete the function even if an exception occurred
214 this->cv.wait(lock, [this, &_f, &isPop, &_flag](){ isPop = this->q.pop(_f); return isPop || this->isDone || _flag; });
std::vector< std::unique_ptr< std::thread > > threads
Definition: ctpl.h:226
thread_pool & operator=(const thread_pool &)
boost::lockfree::queue< std::function< void(int id)> * > q
Definition: ctpl.h:228
std::vector< std::shared_ptr< std::atomic< bool > > > flags
Definition: ctpl.h:227
auto push(F &&f, Rest &&... rest) -> std::future< decltype(f(0, rest...))>
Definition: ctpl.h:152
thread_pool(int nThreads, int queueSize=_ctplThreadPoolLength_)
Definition: ctpl.h:53
Definition: ctpl.h:48