
I've been trying to use boost::thread with a movable structure (see end for code + error). From the online manual ( http://www.boost.org/doc/libs/1_36_0/doc/html/thread/thread_management.html#... ) template <class F, class A1, class A2, ...> thread(F f, A1 a1, A2 a2, ...); Preconditions: F and each An must by copyable or movable. Effects: As if thread(boost::bind(f,a1,a2,...)). Consequently, f and each an are copied into internal storage for access by the new thread. I've been running into a problem with this however. The use of boost::bind means that F needs to have a copy constructor, which seems odd as the manual says "or movable". Am I doing something wrong, or is this an oversight, or what? Regards, Daryl. ---------- Code: (built with: gcc version 4.4.0 20080831 (experimental) (GCC) g++-trunk -o move_thread move_thread.cpp --std=c++0x /usr/local/lib/libboost_thread-gcc43-mt.a) ---------- #include <iostream> #include <vector> #include <boost/preprocessor/iteration/iterate.hpp> #include <boost/thread.hpp> using std::cout; using std::endl; using std::vector; using boost::thread; struct S { S(int) { cout << "S()" << endl; } S(S &&) { cout << "S() move" << endl; } void operator()(int i) { cout << "Thread running [" << i << "]" << endl; } S(S const &) = delete; }; int main() { vector<thread> v; for (int i = 0; i < 10; ++i) { v.push_back(thread(S(i), i)); } for (int i = 0; i < 10; ++i) { v[i].join(); } } ---------- Error: ---------- In file included from /usr/local/include/boost/thread/thread.hpp:22, from /usr/local/include/boost/thread.hpp:13, from move_thread.cpp:4: move_thread.cpp: In constructor ‘boost::thread::thread(F, A1) [with F = S, A1 = int]’: move_thread.cpp:26: instantiated from here move_thread.cpp:18: error: deleted function ‘S::S(const S&)’ /usr/local/include/boost/thread/detail/thread.hpp:227: error: used here /usr/local/include/boost/thread/detail/thread.hpp:227: error: initializing argument 2 of ‘boost::_bi::bind_t<R, F, typename boost::_bi::list_av_1<A1>::type> boost::bind(boost::type<R>, F, A1) [with R = void, F = S, A1 = int]’

Daryl Haresign:
I've been running into a problem with this however. The use of boost::bind means that F needs to have a copy constructor, which seems odd as the manual says "or movable".
Am I doing something wrong, or is this an oversight, or what?
You aren't doing anything wrong; boost::bind doesn't support move-only objects, at least not yet.
participants (2)
-
Daryl Haresign
-
Peter Dimov