Boost logo

Boost Users :

From: Mark Sizer (boost_at_[hidden])
Date: 2003-10-08 14:50:18


I converted existing code to boost::thread, so I didn't have to make
this design decision, it was already made.

My threaded object is of handle class. The actual thread processing (and
member variables, including a socket) takes place in the body object.

It doesn't matter how many times the handle is copied (and destroyed)
becaue they all point to the same body.

There is, no doubt, a more efficient way of doing this (e.g. some sort
of shared pointer). I didn't have to do the research to figure it out,
though.

Good luck,
  - Mark

Huck finn wrote:

> Ok, now I see that my object is being copied. But for the lines :
>
> FakeClass *item1 = new FakeClass(1);//,item2(2);
> group.create_thread(*item1);
>
> I get :
>
> FakeClass #1 says : I'm alive!
> FakeClass #1 says : Being Copied!!
> FakeClass #1 says : Being Copied!!
> FakeClass #1 says : Being Copied!!
> FakeClass #1 says : I'm being destroyed!
> FakeClass #1 says : I'm being destroyed!
> FakeClass #1 says : Being Copied!!
> FakeClass #1 says : I'm being destroyed!
> Thread for FakeClass #1 has been started!
> FakeClass #1 says : I'm being destroyed!
> main ending...
>
>
> The copy constructor is called 4 times!!! And it is called 3 times
> before the thread has even started! Is there a way to avoid that ?
>
> I was going to use the thread_group to manage the connection to a simple
> server applications, so that all the threads would hold info about the
> socket used for connection, etc... And that if the objectdestructor is
> called, the connection to the socket would be closed... With my object
> being destroyed 3 times before the thread has started, it gets a bit
> hard to manage that way... Any clue on how to use the threads so that it
> would work?
>
> thanks,
>
> Simon
>
> _________________________________________________________________
> MSN Messenger : discutez en direct avec vos amis !
> http://messenger.fr.msn.ca/


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