[Boost][Thread] Non-copyable boost::thread

Hi, The Boost.Thread documentation points out that boost::thread is non- copyable but then goes on to provide rational for why it should be possible to return by value from make_thread_return_local(). Intel-11.1 on Darwin is a recent compiler that will not compile this code. [ from libs/thread/test/test_thread_return_local.cpp ] boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; } The same error message is generated in both debug and release builds on Darwin (though strangely it doesn't appear to be an error with Intel 11.1 on Linux). "/opt/intel/Compiler/11.1/067/bin/intel64/icpc" -xc++ -w1 -O0 -g - inline-level=0 -vec-report0 -DBOOST_ALL_NO_LIB=1 - DBOOST_TEST_NO_AUTO_LINK=1 -DBOOST_THREAD_POSIX - DBOOST_THREAD_USE_LIB=1 -I".." -c -o "/Volumes/Scratch/kbelco/boost/ results/boost/bin.v2/libs/thread/test/ test_thread_return_local_lib.test/intel-darwin-11.1/debug/threading- multi/test_thread_return_local.o" "../libs/thread/test/ test_thread_return_local.cpp" ../libs/thread/test/test_thread_return_local.cpp(16): error #373: "boost::thread::thread(boost::thread &)" (declared at line 111 of "../ boost/thread/detail/thread.hpp") is inaccessible return t; ^ Any ideas how to work around this failure? Thanks. -- Noel

"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
[ from libs/thread/test/test_thread_return_local.cpp ]
boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; }
The same error message is generated in both debug and release builds on Darwin (though strangely it doesn't appear to be an error with Intel 11.1 on Linux).
../libs/thread/test/test_thread_return_local.cpp(16): error #373: "boost::thread::thread(boost::thread &)" (declared at line 111 of "../ boost/thread/detail/thread.hpp") is inaccessible return t; ^
Any ideas how to work around this failure?
Explicitly move the return value: return std::move(t); or even return std::thread(std::move(t)); Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
[ from libs/thread/test/test_thread_return_local.cpp ]
boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; }
The same error message is generated in both debug and release builds on Darwin (though strangely it doesn't appear to be an error with Intel 11.1 on Linux).
../libs/thread/test/test_thread_return_local.cpp(16): error #373: "boost::thread::thread(boost::thread &)" (declared at line 111 of "../ boost/thread/detail/thread.hpp") is inaccessible return t; ^
Any ideas how to work around this failure?
Explicitly move the return value:
return std::move(t);
or even
return std::thread(std::move(t));
Yup, that's what I figured. But this compiler doesn't have std::move(). test_thread_return_local.cpp(17): error: namespace "std" has no member "move" return std::move(t); ^ Any other ideas on how to get these Darwin / Intel tests running Anthony? Would the Boost.Move library currently under review work here? -- Noel

----- Original Message ----- From: "Belcourt, Kenneth" <kbelco@sandia.gov> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 5:41 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
[ from libs/thread/test/test_thread_return_local.cpp ]
boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; }
The same error message is generated in both debug and release builds on Darwin (though strangely it doesn't appear to be an error with Intel 11.1 on Linux).
../libs/thread/test/test_thread_return_local.cpp(16): error #373: "boost::thread::thread(boost::thread &)" (declared at line 111 of "../ boost/thread/detail/thread.hpp") is inaccessible return t; ^
Any ideas how to work around this failure?
Explicitly move the return value:
return std::move(t);
or even
return std::thread(std::move(t));
Yup, that's what I figured. But this compiler doesn't have std::move().
test_thread_return_local.cpp(17): error: namespace "std" has no member "move" return std::move(t); ^
Any other ideas on how to get these Darwin / Intel tests running Anthony? Would the Boost.Move library currently under review work here?
If you are using Boost.Thread as I suspect, try return boost::move(t); or even return boost::thread(boost::move(t)); Best, Vicente

On May 17, 2010, at 9:49 AM, vicente.botet wrote:
----- Original Message ----- From: "Belcourt, Kenneth" <kbelco@sandia.gov> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 5:41 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
[ from libs/thread/test/test_thread_return_local.cpp ]
boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; }
The same error message is generated in both debug and release builds on Darwin (though strangely it doesn't appear to be an error with Intel 11.1 on Linux).
../libs/thread/test/test_thread_return_local.cpp(16): error #373: "boost::thread::thread(boost::thread &)" (declared at line 111 of "../ boost/thread/detail/thread.hpp") is inaccessible return t; ^
Any ideas how to work around this failure?
Explicitly move the return value:
return std::move(t);
or even
return std::thread(std::move(t));
Yup, that's what I figured. But this compiler doesn't have std::move().
test_thread_return_local.cpp(17): error: namespace "std" has no member "move" return std::move(t); ^
Any other ideas on how to get these Darwin / Intel tests running Anthony? Would the Boost.Move library currently under review work here?
If you are using Boost.Thread as I suspect, try return boost::move(t); or even return boost::thread(boost::move(t));
Hi Vicente, I'd considered this already but I'm not sure how to implement the move copy and assign constructors for Boost.Thread that Boost.Move requires. Here's the changes I've made, just missing the implementations for move copy and assign. [ boost/thread/detail/thread.hpp ] private: BOOST_MOVABLE_BUT_NOT_COPYABLE(thread) public: // move ctor thread(BOOST_RV_REF(thread) x); // move assign thread& operator=(BOOST_RV_REF(thread) x); private: // thread(thread&); // thread& operator=(thread&); Since Boost.Thread has it's own partial move implementation in boost::detail::thread_move, it seems that some work is necessary to integrate (or re-implement) thread_move in terms of boost::move. That's why I thought I'd ping Anthony and see if this is even worth considering. -- Noel

----- Original Message ----- From: "Belcourt, Kenneth" <kbelco@sandia.gov> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 6:31 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
On May 17, 2010, at 9:49 AM, vicente.botet wrote:
----- Original Message ----- From: "Belcourt, Kenneth" <kbelco@sandia.gov> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 5:41 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
[ from libs/thread/test/test_thread_return_local.cpp ]
boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; }
The same error message is generated in both debug and release builds on Darwin (though strangely it doesn't appear to be an error with Intel 11.1 on Linux).
../libs/thread/test/test_thread_return_local.cpp(16): error #373: "boost::thread::thread(boost::thread &)" (declared at line 111 of "../ boost/thread/detail/thread.hpp") is inaccessible return t; ^
Any ideas how to work around this failure?
Explicitly move the return value:
return std::move(t);
or even
return std::thread(std::move(t));
Yup, that's what I figured. But this compiler doesn't have std::move().
test_thread_return_local.cpp(17): error: namespace "std" has no member "move" return std::move(t); ^
Any other ideas on how to get these Darwin / Intel tests running Anthony? Would the Boost.Move library currently under review work here?
If you are using Boost.Thread as I suspect, try return boost::move(t); or even return boost::thread(boost::move(t));
Hi Vicente,
I'd considered this already but I'm not sure how to implement the move copy and assign constructors for Boost.Thread that Boost.Move requires.
Here's the changes I've made, just missing the implementations for move copy and assign.
[ boost/thread/detail/thread.hpp ]
private: BOOST_MOVABLE_BUT_NOT_COPYABLE(thread)
public: // move ctor thread(BOOST_RV_REF(thread) x);
// move assign thread& operator=(BOOST_RV_REF(thread) x);
private: // thread(thread&); // thread& operator=(thread&);
Since Boost.Thread has it's own partial move implementation in boost::detail::thread_move, it seems that some work is necessary to integrate (or re-implement) thread_move in terms of boost::move. That's why I thought I'd ping Anthony and see if this is even worth considering.
As you said Boost.Thread implements in his way its own move semantics. It defines already an overload for boost::move(thread&) You don't need to integrate Boost.Thread and Boost.Move as far as you don't wanted to use the Boost.Container library, that is is not reviewed yet. I guess Anthony, the author of Boost.Thread will replace its implementation by one using Boost.Move once Boost.Move will be released (if accepted of course ;). I see that the Boost.Thread documentation don't includes any reference to the provided boost::move. Anthony, have you removed it? Best, Vicente

"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
On May 17, 2010, at 9:49 AM, vicente.botet wrote:
----- Original Message ----- From: "Belcourt, Kenneth" <kbelco@sandia.gov> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 5:41 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
[ from libs/thread/test/test_thread_return_local.cpp ]
boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); return t; }
Any ideas how to work around this failure?
Explicitly move the return value:
return std::move(t);
or even
return std::thread(std::move(t));
Yup, that's what I figured. But this compiler doesn't have std::move().
Any other ideas on how to get these Darwin / Intel tests running Anthony? Would the Boost.Move library currently under review work here?
If you are using Boost.Thread as I suspect, try return boost::move(t); or even return boost::thread(boost::move(t));
I'd considered this already but I'm not sure how to implement the move copy and assign constructors for Boost.Thread that Boost.Move requires.
Vicente is right that I meant boost::move and boost::thread. boost::move is overloaded for boost::thread and anything else that uses boost::thread_move, so the above should "just work". See libs/thread/test/test_thread_move.cpp and libs/thread/test/test_thread_move_return.cpp
Since Boost.Thread has it's own partial move implementation in boost::detail::thread_move, it seems that some work is necessary to integrate (or re-implement) thread_move in terms of boost::move. That's why I thought I'd ping Anthony and see if this is even worth considering.
Yes, there's a bit of work necessary to integrate Boost.Thread move support and Boost.Move, but it should still support move semantics through its own mechanism in the mean time. As far as the specific test goes --- it's a characterisation test that identifies whether or not the platform/compiler supports the particular scenario. Some do, some don't. I think technically the ones that don't are more conforming under C++98, but it's a useful extension in this case. Under C++0x, with rvalue-ref move support, it is required to work. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

On May 17, 2010, at 2:54 PM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
On May 17, 2010, at 9:49 AM, vicente.botet wrote:
From: "Belcourt, Kenneth" <kbelco@sandia.gov>
On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Intel-11.1 on Darwin is a recent compiler that will not compile this code.
Explicitly move the return value:
If you are using Boost.Thread as I suspect, try return boost::move(t);
With this syntax the compiler gives the inaccessible message, though it's a warning not an error.
return boost::thread(boost::move(t));
But this works okay and is warnings free. I've attached a patch that should fix this. Okay to commit?
Vicente is right that I meant boost::move and boost::thread.
Right, I now see that, thanks.
boost::move is overloaded for boost::thread and anything else that uses boost::thread_move, so the above should "just work".
See libs/thread/test/test_thread_move.cpp and libs/thread/test/test_thread_move_return.cpp
Since Boost.Thread has it's own partial move implementation in boost::detail::thread_move, it seems that some work is necessary to integrate (or re-implement) thread_move in terms of boost::move. That's why I thought I'd ping Anthony and see if this is even worth considering.
Yes, there's a bit of work necessary to integrate Boost.Thread move support and Boost.Move, but it should still support move semantics through its own mechanism in the mean time.
As far as the specific test goes --- it's a characterisation test that identifies whether or not the platform/compiler supports the particular scenario. Some do, some don't. I think technically the ones that don't are more conforming under C++98, but it's a useful extension in this case. Under C++0x, with rvalue-ref move support, it is required to work.
Okay, thanks for the explanation. We can't use Boost libraries that have failures though expected failures are okay. That's why I'm trying to get Boost.Thread with Intel on Darwin working. I appreciate all the help. -- Noel Index: test_thread_return_local.cpp =================================================================== --- test_thread_return_local.cpp (revision 62066) +++ test_thread_return_local.cpp (working copy) @@ -13,7 +13,11 @@ boost::thread make_thread_return_local(boost::thread::id* the_id) { boost::thread t(do_nothing,the_id); +#if defined(__APPLE__) && defined(__INTEL_COMPILER) + return boost::thread(boost::move(t)); +#else return t; +#endif }

"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
On May 17, 2010, at 2:54 PM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
On May 17, 2010, at 9:49 AM, vicente.botet wrote:
From: "Belcourt, Kenneth" <kbelco@sandia.gov>
On May 17, 2010, at 2:25 AM, Anthony Williams wrote:
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
> Intel-11.1 on Darwin is a recent compiler that will not compile > this code.
Explicitly move the return value:
If you are using Boost.Thread as I suspect, try return boost::move(t);
With this syntax the compiler gives the inaccessible message, though it's a warning not an error.
return boost::thread(boost::move(t));
But this works okay and is warnings free.
I've attached a patch that should fix this. Okay to commit?
No. It changes what is being tested.
We can't use Boost libraries that have failures though expected failures are okay. That's why I'm trying to get Boost.Thread with Intel on Darwin working.
test_thread_return_local is already marked up as an expected failure for Intel/Darwin. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 10:54 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Vicente is right that I meant boost::move and boost::thread.
boost::move is overloaded for boost::thread and anything else that uses boost::thread_move, so the above should "just work".
See libs/thread/test/test_thread_move.cpp and libs/thread/test/test_thread_move_return.cpp
Since Boost.Thread has it's own partial move implementation in boost::detail::thread_move, it seems that some work is necessary to integrate (or re-implement) thread_move in terms of boost::move. That's why I thought I'd ping Anthony and see if this is even worth considering.
Yes, there's a bit of work necessary to integrate Boost.Thread move support and Boost.Move, but it should still support move semantics through its own mechanism in the mean time.
Anthony, where is documented the boost::move function, I don't reach to find it? Best, Vicente

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, May 17, 2010 10:54 PM Subject: Re: [boost] [Boost][Thread] Non-copyable boost::thread
"Belcourt, Kenneth" <kbelco@sandia.gov> writes:
Vicente is right that I meant boost::move and boost::thread.
boost::move is overloaded for boost::thread and anything else that uses boost::thread_move, so the above should "just work".
See libs/thread/test/test_thread_move.cpp and libs/thread/test/test_thread_move_return.cpp
Since Boost.Thread has it's own partial move implementation in boost::detail::thread_move, it seems that some work is necessary to integrate (or re-implement) thread_move in terms of boost::move. That's why I thought I'd ping Anthony and see if this is even worth considering.
Yes, there's a bit of work necessary to integrate Boost.Thread move support and Boost.Move, but it should still support move semantics through its own mechanism in the mean time.
Anthony, where is documented the boost::move function, I don't reach to find it?
Missing. I guess I never wrote it. Added on trunk. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
participants (3)
-
Anthony Williams
-
Belcourt, Kenneth
-
vicente.botet