Boost logo

Boost :

Subject: Re: [boost] [Thread] Non-copyable boost::thread
From: Belcourt, Kenneth (kbelco_at_[hidden])
Date: 2010-05-17 12:31:35


On May 17, 2010, at 9:49 AM, vicente.botet wrote:

> ----- Original Message -----
> From: "Belcourt, Kenneth" <kbelco_at_[hidden]>
> To: <boost_at_[hidden]>
> 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_at_[hidden]> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk