
On Sun, Jan 15, 2012 at 06:25:52PM -0600, Chris Cleeland wrote:
The spawned thread gets an instance of Task, but it's not the same instance as from the main.
What is the rationale?
Functors in general should be expected to be copied, so it might not be an explicit decision. It is, however, a good decision. The thread of execution generally outlives the scope where the thread is started. If the thread used a reference to the functor, then pretty much _all_ cases would force the user to store away function objects elsewhere and destroy them only when the thread has terminated completely. It would also prevent the use of temporaries as thread callables. If you want to get reference semantics, use a reference_wrapper. boost::thread t(boost::ref(task)); will have the reference semantics you crave. -- Lars Viklund | zao@acc.umu.se