Boost logo

Boost :

From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2004-11-29 18:07:27


On Mon, 29 Nov 2004 16:41:49 -0500, Beman Dawes <bdawes_at_[hidden]> wrote:

> Caleb, could you please do one more thing on this: read the docs and see if
> your answer is obvious from the docs. If not, could you please submit a
> path clarifying the docs the need to join.

FYI I've managed to produce this OOM condition with Solaris pthreads,
so its not a Linux or Boost issue. Attached is a simple program that
probes this limit using only pthreads calls. On Solaris I hit the
memory limit after 2,714 threads and on Linux 2.4.21-9.ELsmp I hit it
at 1,020.

I don't think the memory leak issue is discussed anywhere in the
Boost.Threads documentation, or if it is I'm unable to find it.
Because threads are automatically detached in the thread dtor, the
only way for this leak to take place is by creating threads on the
heap and not deleting/joining them, which is what the OP was doing.

There is the following text in http://boost.org/doc/html/thread.html,
under Description:

"A thread of execution is said to be "finished" or to have "finished
execution" when its initial function returns or is terminated. This
includes completion of all thread cleanup handlers, and completion of
the normal C++ function return behaviors, such as destruction of
automatic storage (stack) objects and releasing any associated
implementation resources."

Perhaps the following paragraph could be added in another callout at
the bottom of this section or below the "thread
construct/copy/destruct" section:

"With some platform-specific thread libraries (notably POSIX threads),
the stack space of a joinable thread is not automatically cleaned up
until it has been joined. When thread objects are allocated on the
heap (e.g. via operator new or thread_group::create), it is the
responsibility of the user of Boost.Threads to ensure these threads
have been either detached or joined in order to avoid memory leaks."

Also, here are some formatting oddities I noticed in the documentation
from my reading just now:

On page http://boost.org/doc/html/threads/rationale.html, in the
Comparison section:

* 2. Comparison: creation of a thread that's later joined

    create_thread(&bar);thrd->join();

should be

    create_thread(&bar);
    thrd->join();

* 4. Comparison: creation of several threads in a loop which are later joined.

    for (int i= 0; i<NUM_THREADS;
            ++i)threads[i]->join();

should be

    for (int i= 0; i<NUM_THREADS; ++i)
        threads[i]->join();

-- 
Caleb Epstein
caleb dot epstein at gmail dot com



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk