Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Thread and Boost.Function problems?
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2010-03-04 22:18:40


El 04/03/2010 10:03 p.m., anony escribió:
> I have this situation:
>
> void my_thread(std::string const& a, std::string const& b)
> {
> }
>
> void spawner()
> {
> boost::thread(boost::function<void (std::string const&, std::string
> const&>(my_thread), "bla", "lala");
> }
>
> This works, but is it possible that the string temporaries are destroyed
> before the thread starts running?
>

Extract from Boost.Thread documentation at
http://www.boost.org/doc/libs/1_42_0/doc/html/thread/thread_management.html#thread.thread_management.thread.multiple_argument_constructor

"Thread Constructor with arguments

template <class F,class A1,class A2,...>
thread(F f,A1 a1,A2 a2,...);

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."

So whether the string temporaries are destroyed is irrelevant; my_thread
function will be called with *copies* of those temporaries.

Agustín K-ballo Bergé.-
http://talesofcpp.blogspot.com


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