Boost logo

Boost Users :

Subject: Re: [Boost-users] How to pass a shared_ptr to a thread.
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-12-03 22:35:31


On Wed, Dec 3, 2008 at 22:29, Jason Cipriani <jason.cipriani_at_[hidden]> wrote:
>
> Sorry if this is a stupid question, but the only thing I could think
> of was "(LPVOID)new shared_ptr(p)", but that means each thread must
> explicitly delete the new shared_ptr and that kind of defeats the
> purpose!
>

That's the usual way to pass things through void* callbacks.

If you don't want to do that, then use boost.thread, which does that
trick for you with boost.function so you can use arbitrary functors,
allowing state.

    boost::thread mythread(boost::bind(threadproc, something));


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