Boost logo

Boost Users :

From: Phil Endecott (spam_from_boost_users_at_[hidden])
Date: 2005-10-25 12:30:54


Dear Experts,

The boost::thread documentation says:

Just as the lifetime of a file may be different from the lifetime of an
iostream object which represents the file, the lifetime of a thread of
execution may be different from the thread object which represents the
thread of execution. In particular, after a call to join(), the thread
of execution will no longer exist even though the thread object
continues to exist until the end of its normal lifetime. The converse is
also possible; if a thread object is destroyed without join() first
having been called, the thread of execution continues until its initial
function completes.

That's fine, but it's not what I'm looking for right now. Can anyone
point me to some code - perhaps adding a layer on top of boost::thread -
that ties object lifetime to thread lifetime in some way? (I'm
imagining a dynamically-allocated object the deletes itself when the
thread's initial function terminates, and that kills the thread if it
(the object) is deleted first.)

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.

My guess is that this could be done in just a few lines of code, but
there are probably lots of race conditions to worry about. Any
suggestions anyone?

Cheers,

--Phil.


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