Boost logo

Boost Users :

Subject: Re: [Boost-users] Automatic thread join
From: Lloyd (lloyd_at_[hidden])
Date: 2010-01-08 05:34:38


yes I too feel that you are right, and I think that the problem is with the shared_ptr (shared_from_this()) . Can anyone suggest a way to reduce the shared_ptr reference count at the end of the thread execution, so that all referece will be reduced and the respective destructor will be called.

Thanks a lot,
  Lloyd
  ----- Original Message -----
  From: Shiou Ming Lee
  To: boost-users_at_[hidden]
  Sent: Friday, January 08, 2010 3:20 PM
  Subject: Re: [Boost-users] Automatic thread join

  On Fri, Jan 8, 2010 at 4:41 PM, Lloyd <lloyd_at_[hidden]> wrote:

    This is the way I create new thread

    void TCPConnection::MyFunction()
    {
     ....
    boost::thread *th=new boost::thread(boost::bind(&TCPConnection::ExecutionRoutine,shared_from_this(),Command));
    ....
    }

    when the ExecutionRoutine() finishes its execution, naturally the destructor of the TCPConnection class has to be called. But it never gets called! But if call a join from someware else (th->join()) the destructor of the TCPConnection class gets called and the connection is terminated, otherwise the it continues in the connected state!!

    What could be the mistake I am doing?

  If not mistaken that's the normal behavior which requires parent thread to join() its child threads, for proper release of thread resources, and I don't think it is specific to Boost.Thread. I might be wrong though.
   

    Thanks,
     Lloyd

      What kind of waist?
      I guess the name of the function mislead you. join() in this context
      means "wait" - nothing more.
      _______________________________________________
      Boost-users mailing list
      Boost-users_at_[hidden]
      http://lists.boost.org/mailman/listinfo.cgi/boost-users

    ___________________
    Happy New Year 2010

    _______________________________________________
    Boost-users mailing list
    Boost-users_at_[hidden]
    http://lists.boost.org/mailman/listinfo.cgi/boost-users

------------------------------------------------------------------------------

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users

___________________
Happy New Year 2010



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