File tree 1 file changed +6
-5
lines changed
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,6 @@ auto ThreadPool::enqueue(F&& f, Args&&... args)
60
60
-> std::future<typename std::result_of<F(Args...)>::type>
61
61
{
62
62
typedef typename std::result_of<F (Args...)>::type return_type;
63
-
64
- // don't allow enqueueing after stopping the pool
65
- if (stop)
66
- throw std::runtime_error (" enqueue on stopped ThreadPool" );
67
63
68
64
auto task = std::make_shared< std::packaged_task<return_type ()> >(
69
65
std::bind (std::forward<F>(f), std::forward<Args>(args)...)
@@ -72,7 +68,12 @@ auto ThreadPool::enqueue(F&& f, Args&&... args)
72
68
std::future<return_type> res = task->get_future ();
73
69
{
74
70
std::unique_lock<std::mutex> lock (queue_mutex);
75
- tasks.push ([task](){ (*task)(); });
71
+
72
+ // don't allow enqueueing after stopping the pool
73
+ if (stop)
74
+ throw std::runtime_error (" enqueue on stopped ThreadPool" );
75
+
76
+ tasks.emplace ([task](){ (*task)(); });
76
77
}
77
78
condition.notify_one ();
78
79
return res;
You can’t perform that action at this time.
0 commit comments