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
www.selestial.com

Example code.

class myclass {
public:
    // Lots of local data here
    void operator() () {
        do_thread_stuff();
    };

    // CTOR
    myclass(){
        do_some_initialisation_stuff();
    };

   // DTOR
   ~myclass(){
        do_some_cleanup_stuff();
    };

   // Lots of member funcs
   ...
};

void main (void){

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

}


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