Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Aug 2006 20:10:20 GMT
From:      Daniel Eischen <deischen@freebsd.org>
To:        freebsd-threads@FreeBSD.org
Subject:   Re: threads/101323: fork(2) in threaded programs broken. 
Message-ID:  <200608032010.k73KAKHf021183@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR threads/101323; it has been noted by GNATS.

From: Daniel Eischen <deischen@freebsd.org>
To: Poul-Henning Kamp <phk@phk.freebsd.dk>
Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-threads@freebsd.org
Subject: Re: threads/101323: fork(2) in threaded programs broken. 
Date: Thu, 3 Aug 2006 16:04:49 -0400 (EDT)

 On Thu, 3 Aug 2006, Poul-Henning Kamp wrote:
 
 > In message <Pine.GSO.4.64.0608031417260.13543@sea.ntplx.net>, Daniel Eischen wr
 > ites:
 >
 >> No, that's not nearly enough.  This has been discussed in
 >> -threads before.
 >>
 >> Forking from a multi-threaded program is just like an
 >> asynchronous signal in an unthreaded program.  You have
 >> no idea what state any of the libraries or application data
 >> is in.
 >
 > ... Unless of course, the programmer too great care to make
 > sure he did, and therefore assumes that fork() will actually
 > be safe.
 >
 > In my case, I know the exact state of the entire process
 > and I know 100% certain that there are no locks held which
 > will affect the forked copy.
 >
 > ... except that holding all malloc's locks screws me over :-(
 >
 > I will agree that there is no "perfect" solution, but that is
 > not what I'm after, I'm after "works in controlled circumstances.
 >
 > I would argue that an implementation that does:
 >
 > 	hold any library locks we want to handle
 > 	fork
 > 	if (parent)
 > 		release those locks again
 > 		return
 > 	else
 > 		unlock all locks (since they cannot possibly
 > 		make sense in the child in a locked state)
 > 		return
 
 There's no easy way to hold all library locks.  They are
 littered in libc and libpthread and the application doesn't
 have access to them.  You would have to teach libc to
 record these locks and export a function to lib<thread>
 to lock and unlock these them.
 
 > That would go a long way towards a "works if you're careful"
 > implementation.
 
 -- 
 DE



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