Boost logo

Threads-Devel :

Subject: [Threads-devel] Threads and copy constructors...
From: oneflewover (thedeerhunter1978_at_[hidden])
Date: 2012-02-18 14:37:54


In the code snippet below, I have one functor that I pass to one
thread. As expected, the constructor is called once, but the copy
constructor is called four times! As a result, the destructor is
called five times.

Can someone please explain to me why the copy constructor is called
four times? Thanks.

===================================================

class c1
{
    public:

        c1() { }

        c1(const c1& c) { }

        void operator()() { }

        ~c1() { }
};

int main()
{
    c1 c; // constructor called once here

    //
    // copy constructor called four times here; why?
    //
    boost::thread t1( c1 );

    //
    // destructor called four times here
    //
    t1.join();

    //
    // destructor called once here
    //
}


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk