Boost logo

Boost :

From: Tim Laplaca (tlaplaca_at_[hidden])
Date: 2004-11-29 15:24:07

Thank you much for figuring this out.

Can you post your code to the list?


-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Caleb Epstein
Sent: Monday, November 29, 2004 2:30 PM
To: boost_at_[hidden]
Subject: Re: [boost] Thread: Why is my prog aborting after 283 or so

On Mon, 29 Nov 2004 13:57:00 -0500, Tim Laplaca <tlaplaca_at_[hidden]>
> I went ahead and submitted a bug report in the Sourceforge bug tracker
> for this issue:
> [ 1075456 ] Boost::thread under Linux crashes after 200 to 400 threads
> I made it a high priority, since it's a program crash. I attached my
> program to reproduce the problem, so hopefully the person who fixes
> will be able to reproduce the crash pretty easily.
> -- Tim

I've compiled the test program and can confirm the behavior on Red Hat
Advanced Server 3.0 and Debian GNU/Linux running stock kernel 2.6.7,
though I got up over 1100 threads on each of these before the program

The problem isn't one of threads so much as one of memory however.
The program just runs out of memory because you are not join'ing the
exited threads. According to the manual page for pthread_join on my
Linux box:

       When a joinable thread terminates, its memory resources
       descriptor and stack) are not deallocated until another thread
       pthread_join on it. Therefore, pthread_join must be called
once for
       each joinable thread created to avoid memory leaks.

Indeed, changing the code to use individual threads instead of a
thread group and joining each after the sleep call fixes the leak and
the crash. I've successfully spawned tens of thousands of threads on
Linux with this change in place.

Caleb Epstein
caleb dot epstein at gmail dot com
Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at