RE: [boost] Thread: Why is my prog aborting after 283 or so threads?

Caleb Epstein wrote:
You can make a thread non-joinable, in which case it will automatically clean up after itself, by deleting the heap-allocated thread objects you create. The thread will continue to run, but it will become "detached" and you won't face this resource issue on thread exit.
I would have never thought of that, sounds dangerous! I tried it and it seems to work though. Is that pretty safe? Specifically, I'm spawning my threads like this: boost::thread *ptr = thrds.create_thread(boost::bind (threadfunc, totalthreads, xx+1)); delete ptr; (where thrds is a thread group) My sample prog has made over 300,000 threads so far with this method, so it seems pretty stable. Tim

On Wed, 1 Dec 2004 16:29:59 -0500, Tim Laplaca <tlaplaca@voiceglo.com> wrote:
I would have never thought of that, sounds dangerous! I tried it and it seems to work though. Is that pretty safe?
100% safe. See the discussion here: http://boost.org/doc/html/thread.html#threadconstruct-copy-destruct That said, it might be nice to have an argument to the boost::thread ctor to start a detached thread w/o needing to resort to using the heap. -- Caleb Epstein caleb dot epstein at gmail dot com

Just use an auto variable: // some code { boost::thread t(&some_proc); } // thread detached // more code Bruno Martínez On Wed, 1 Dec 2004 17:10:57 -0500, Caleb Epstein <caleb.epstein@gmail.com> wrote:
On Wed, 1 Dec 2004 16:29:59 -0500, Tim Laplaca <tlaplaca@voiceglo.com> wrote:
I would have never thought of that, sounds dangerous! I tried it and it seems to work though. Is that pretty safe?
100% safe. See the discussion here:
http://boost.org/doc/html/thread.html#threadconstruct-copy-destruct
That said, it might be nice to have an argument to the boost::thread ctor to start a detached thread w/o needing to resort to using the heap.
participants (3)
-
Bruno Martínez Aguerre
-
Caleb Epstein
-
Tim Laplaca