summaryrefslogtreecommitdiff
path: root/boost/thread/executors/basic_thread_pool.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/thread/executors/basic_thread_pool.hpp')
-rw-r--r--boost/thread/executors/basic_thread_pool.hpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/boost/thread/executors/basic_thread_pool.hpp b/boost/thread/executors/basic_thread_pool.hpp
index 64ba1e90e0..e0d4df2c76 100644
--- a/boost/thread/executors/basic_thread_pool.hpp
+++ b/boost/thread/executors/basic_thread_pool.hpp
@@ -13,7 +13,7 @@
#include <boost/thread/detail/config.hpp>
#include <boost/thread/detail/delete.hpp>
#include <boost/thread/detail/move.hpp>
-#include <boost/thread/scoped_thread.hpp>
+#include <boost/thread/thread.hpp>
#include <boost/thread/concurrent_queues/sync_queue.hpp>
#include <boost/thread/executors/work.hpp>
#include <boost/thread/csbl/vector.hpp>
@@ -30,15 +30,14 @@ namespace executors
/// type-erasure to store the works to do
typedef executors::work work;
private:
- /// the kind of stored threads are scoped threads to ensure that the threads are joined.
+ typedef thread thread_t;
/// A move aware vector type
- typedef scoped_thread<> thread_t;
typedef csbl::vector<thread_t> thread_vector;
- /// the thread safe work queue
- concurrent::sync_queue<work > work_queue;
/// A move aware vector
thread_vector threads;
+ /// the thread safe work queue
+ concurrent::sync_queue<work > work_queue;
public:
/**
@@ -61,7 +60,7 @@ namespace executors
catch (...)
{
std::terminate();
- return false;
+ //return false;
}
}
/**
@@ -88,7 +87,9 @@ namespace executors
{
work task;
queue_op_status st = work_queue.wait_pull(task);
- if (st == queue_op_status::closed) return;
+ if (st == queue_op_status::closed) {
+ return;
+ }
task();
}
}
@@ -222,7 +223,8 @@ namespace executors
{
// signal to all the worker threads that there will be no more submissions.
close();
- // joins all the threads as the threads were scoped_threads
+ // joins all the threads before destroying the thread pool resources (e.g. the queue).
+ join();
}
/**
@@ -264,23 +266,28 @@ namespace executors
* \b Throws: \c sync_queue_is_closed if the thread pool is closed.
* Whatever exception that can be throw while storing the closure.
*/
+ void submit(BOOST_THREAD_RV_REF(work) closure) {
+ work_queue.push(boost::move(closure));
+ }
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template <typename Closure>
void submit(Closure & closure)
{
- work_queue.push(work(closure));
+ submit(work(closure));
}
#endif
void submit(void (*closure)())
{
- work_queue.push(work(closure));
+ submit(work(closure));
}
template <typename Closure>
- void submit(BOOST_THREAD_RV_REF(Closure) closure)
+ void submit(BOOST_THREAD_FWD_REF(Closure) closure)
{
- work_queue.push(work(boost::forward<Closure>(closure)));
+ //submit(work(boost::forward<Closure>(closure)));
+ work w((boost::forward<Closure>(closure)));
+ submit(boost::move(w));
}
/**