Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: threaded programs report bogus process size ? (Nicolas Joly) writes:

>I just noticed that threaded processes may report increasing process
>size of their life ...

libpthread never frees the pthread data structure and associated
thread stack when a thread ends but puts it onto a private queue
("deadqueue") and reclaims it again when a new thread is created.

The reclaim can fail when a new thread is created shortly after
an old thread ended because of a race with the kernel. As a result
a new thread is allocated.

So _some_ leakage is allowed by design.

The problem is that the reclaim operation is only tried for the
thread that ended last (the top of the "deadqueue"). So in a
tight pthread_create/join loop the leaked threads just pile up.

To correct this the reclaim operation should loop over the queue
and try to reclaim any of the dead threads.

                                Michael van Elst
                                "A potential Snark may lurk in every tree."

Home | Main Index | Thread Index | Old Index