Boost logo

Boost Users :

Subject: Re: [Boost-users] storing a boost.thread in a boost shared ptr
From: Sean Farrow (sean.farrow_at_[hidden])
Date: 2011-03-21 05:31:15


Hi:
Yes, that works fine, the following replacement gives the error provided:
boost::shared_ptr<boost::thread> t(boost::bind(&boost::asio::io_service::run, io.get()));
Cheers
Sean.

-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Kulti
Sent: 21 March 2011 09:12
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] storing a boost.thread in a boost shared ptr

On Mon, Mar 21, 2011 at 7:45 AM, Sean Farrow
<sean.farrow_at_[hidden]> wrote:
> Hi:
>
> I'm trying to store a boost.thread in a boost::fusion::vector, and need to
> use a shared ptr, due to boost.thrad being non-copyable
>
> I'm using Microsoft visual c++ 2010.
>
>
>
> I get the following error:
>
>      1>d:\devexpress\mdrlite\mdrlite\mdrlite\midiwidget.cpp(21): error
> C2664: 'boost::shared_ptr<T>::shared_ptr(boost::shared_ptr<T> &&)' : cannot
> convert parameter 1 from 'boost::_bi::bind_t<R,F,L>' to
> 'boost::shared_ptr<T> &&'
>
>                  with
>
>                  [
>
>                      T=boost::thread
>
>                  ]
>
>                  and
>
>                  [
>
>                      R=size_t,
>
>                      F=boost::_mfi::mf0<size_t,boost::asio::io_service>,
>
>
> L=boost::_bi::list1<boost::_bi::value<boost::asio::io_service *>>
>
>                  ]
>
>                  and
>
>                  [
>
>                      T=boost::thread
>
>                  ]
>
>                  Reason: cannot convert from 'boost::_bi::bind_t<R,F,L>' to
> 'boost::shared_ptr<T>'
>
>                  with
>
>                  [
>
>                      R=size_t,
>
>                      F=boost::_mfi::mf0<size_t,boost::asio::io_service>,
>
>
>          L=boost::_bi::list1<boost::_bi::value<boost::asio::io_service *>>
>
>                  ]
>
>                  and
>
>                  [
>
>                      T=boost::thread
>
>                  ]
>
>                  No user-defined-conversion operator available that can
> perform this conversion, or the operator cannot be called
>
> My boost thread is defined as:
>
> boost::thread t(boost::bind(&boost::asio::io_service::run, io.get()));
>
> and io is defined as:
>
> boost::shared_ptr<boost::asio::io_service> io;
>
> I'm obviously overlooking something, I just carn't work out what?
>
> Any help appreciated.
>
> Regards
>
> Sean.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

Hm... are you sure, that line 21 is boost::thread
t(boost::bind(&boost::asio::io_service::run, io.get())); ? I'm trying
to g++ -c following simple function and no errors occurred:
void test()
{
  boost::shared_ptr<boost::asio::io_service> io;
  boost::thread t(boost::bind(&boost::asio::io_service::run, io.get()));
}
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net