Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Oct 2005 16:45:29 +0200
From:      Sven Berkvens-Matthijsse <sven@ilse.net>
To:        Daniel Eischen <deischen@freebsd.org>
Cc:        Marc Olzheim <marcolz@stack.nl>, freebsd-threads@freebsd.org, Marc Olzheim <marcolz@ilse.net>, David Xu <davidxu@freebsd.org>, Sven Berkvens-Matthijsse <sven@ilse.net>
Subject:   Re: threads/76690: fork hang in child for (-lc_r & -lthr)
Message-ID:  <20051024144529.GP22568@ilse.net>
In-Reply-To: <Pine.GSO.4.43.0510241018350.16970-100000@sea.ntplx.net>
References:  <20051024140023.GM22568@ilse.net> <Pine.GSO.4.43.0510241018350.16970-100000@sea.ntplx.net>

next in thread | previous in thread | raw e-mail | index | archive | help
> WRT to malloc() and free() within libc_r, it is always single
> threaded from the library's perspective because no other threads can
> be active at the time of the fork (libc_r is all userspace threads).

Correct. It also takes care to disable the signal handler that may
cause a thread switch in the "thread kernel".

> Probably all that needs to be done is take the malloc lock before
> forking and release it afterwards (like libpthread).

That's possible (and indeed what I do). I decided to lock the other
locks as well because programs (buggy or not) may call those library
functions after the fork (in the child) as well. We can remove those
locks if you wish, none of the functions involved are async-signal-safe,
and programs shouldn't be using them after a fork() in a threaded
program.

> It may even be enough just to set __isthreaded to 0 in the child
> after the fork() before calling any malloc()'s and free()'s so they
> don't try to use the lock.

But then the free() in the child process may be using an unstable
state of the malloc system (because if you don't acquire the lock
before the fork(), malloc() may be busy in the middle of the fork()).

> If __isthreaded is 0 in the child, I don't think any part of libc
> will attempt to use locking.

That's correct.

> If the child tries to create any threads, then bad things may
> happen, but that's the application's fault.

True.

> -- 
> DE

-- 
Sven



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051024144529.GP22568>