From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2004-11-29 14:30:07
On Mon, 29 Nov 2004 13:57:00 -0500, Tim Laplaca <tlaplaca_at_[hidden]> wrote:
> 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 this
> 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
When a joinable thread terminates, its memory resources (thread
descriptor and stack) are not deallocated until another thread performs
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