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