|
Boost : |
Subject: Re: [boost] [thread] why crash launching a thread?
From: Matthew Herrmann (matthew.herrmann_at_[hidden])
Date: 2010-02-01 15:39:41
On 02/02/2010, at 7:18 AM, David M. Cotter wrote:
> i simply call:
>
> foo = new boost::thread(CFork_Preemptive(infoP));
>
> then somewhere INSIDE BOOST, it throws. i have not looked at the boost source about this, i was under the impression that it would never throw to create a thread.
>
> it is intermittant. i can be running for a half hour making new threads left and right, no problem.
boost can throw a thread_resource_error if too many threads are spawned. maybe that's too many threads, maybe the threads are "zombies" (haven't been reclaimed) etc etc.
http://svn.boost.org/svn/boost/tags/release/Boost_1_41_0/libs/thread/src/pthread/thread.cpp
strace -f your program to see if pthread_create returns an error in this intermittent case. i suspect the thread is not returning resources when it joins due to a pthread_create option not being set -- check the options you can set on the thread. also look at the arguments boost uses to create the thread in the strace output and cross reference against the man page for pthread_create to see if they are what you want.
If you don't need to go cross platform, you could just talk to the pthreads library directly -- looks like you're wrapping it in a CThreads library anyway to isolate your app. Less layers to deal with... There was a race condition a long time ago with threads that were created and then immediately joined in 1.31, but that blew up differently.
hth,
Matthew
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk