Reputation: 3692
In the following code the object 'queue' is non-copyable, but is movable due to a std::mutex.
std::generate_n(std::back_inserter(thread_pool),
std::thread::hardware_concurrency,
[&](){return std::thread(handler(), exiting, queue);});
VC++2012 is failing to compile due to a private copy constructor on the mutex. It is failing to generate the copy constructor for queue. Why would anything be trying to copy queue? It appears to me that everything is taking it by reference, thus no copies.
Upvotes: 2
Views: 1328
Reputation: 42554
You are trying to copy queue
by passing it by value to the std::thread
constructor. If you mean to pass a reference, use a wrapper: std::ref(queue)
.
If you really want to move queue
into the std::thread
, you need to pass std::move(queue)
to make it an rvalue. It still won't work though, because of a bug in VS.
Upvotes: 6