Boost logo

Boost Users :

From: Howard Cole (howard.cole_at_[hidden])
Date: 2004-08-27 04:37:39

Hi, I am new to boost::thread but have come across the following problem and
wondered if anyone could help...

The problem is the copy overhead used by the boost::thread /
boost::function0 code. The following code actually creates multiple copies
of myclass rather than using a reference to myclass and due to the size of
the class, this leads to a considerable overhead. I only noticed this
problem because the thread kept failing due to the fact that my constructor
held some socket initialisation code, which was being called multiple times.

Is there a way that I can force the thread class to use references rather
than copying? Looking at the code for the function library, I see that you
can use boost::ref for function classes, any ideas as to how it can be used
in the thread class?

Thanks in advance

Howard Cole

Example code.

class myclass {
    // Lots of local data here
    void operator() () {

    // CTOR

   // DTOR

   // Lots of member funcs

void main (void){

    myclass test_instance;
    boost::thread test_thread(test_instance);


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