Boost logo

Boost Users :

From: Aaron Griffin (aaronmgriffin_at_[hidden])
Date: 2005-10-26 10:41:11


On 10/25/05, Phil Endecott <spam_from_boost_users_at_[hidden]> wrote:
> Dear Experts,
>
> The boost::thread documentation says:
[...snip...]
> The actual application is a sort of daemon; a main loop accepts tcp
> connections, and creates a new thread to handle each one. It normally
> wants to "fire and forget" these threads, and I imagine it creating them
> with new() and then letting them dangle, until they eventually terminate
> and delete themselves.

I may be missing something here, but if thread lifetime and object
lifetime are not tied, why not create the object on the stack (as part
of an accept() loop, using the tcp connection example). The stack
based object will be destroied each loop, but the thread itself will
continue to exist until it ends.

You could also use boost::call_once to "fire and forget"


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