dead lock in forked child

Salvatore Sanfilippo antirez at gmail.com
Fri May 25 02:31:29 PDT 2012


On Fri, May 25, 2012 at 11:02 AM, Jokea <tfengjun at gmail.com> wrote:

> I've found that a forked child runs into dead lock in a multithreaded
> application.

Hello,

just to add that this behavior also happens in Redis, so it is
potentially affecting many users and we saw this bug happening in the
real world.
What appears to happen is that, since fork() only duplicates the
thread calling it, if another thread happens to hold the lock at the
time we fork(), the child will still have the lock as hold but no one
will release it (since the other thread does not exist in the new
process).

Apparently just before forking() jemalloc should do something to make
sure that no lock is hold.

In the specific case of Redis, if this bug is not going to be fixed,
we have the alternative of making sure allocation is not performed at
the time we fork, but this is only currently possible because we do
very little with threads.

Cheers,
Salvatore

-- 
Salvatore 'antirez' Sanfilippo
open source developer - VMware
http://invece.org

Beauty is more important in computing than anywhere else in technology
because software is so complicated. Beauty is the ultimate defence
against complexity.
       — David Gelernter



More information about the jemalloc-discuss mailing list