Boost logo

Boost Users :

Subject: [Boost-users] Why does boost thread copy a functor?
From: Chris Cleeland (chris.cleeland_at_[hidden])
Date: 2012-01-15 19:25:52

I had code similar to the following...

Functor object:

struct Task
 operator()() { // thread main }
 smartfd p;

Note that smartfd is a wrapper around a file descriptor. In its dtor it
closes the fd.

Then, elsewhere I set up an instance of Task and spawn it with

Task t;
t.p = // open file descriptor

boost::thread thr(t);

The spawned thread gets an instance of Task, but it's not the same instance
as from the main.

What is the rationale?

Chris Cleeland

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at