From owner-freebsd-threads@FreeBSD.ORG Thu Aug 3 20:04:50 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E1A1C16A4DE; Thu, 3 Aug 2006 20:04:50 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7CEDF43D73; Thu, 3 Aug 2006 20:04:50 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.7/8.13.7/NETPLEX) with ESMTP id k73K4nxu003459; Thu, 3 Aug 2006 16:04:49 -0400 (EDT) Date: Thu, 3 Aug 2006 16:04:49 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Poul-Henning Kamp In-Reply-To: <49575.1154630696@critter.freebsd.dk> Message-ID: References: <49575.1154630696@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-threads@freebsd.org Subject: Re: threads/101323: fork(2) in threaded programs broken. X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Aug 2006 20:04:51 -0000 On Thu, 3 Aug 2006, Poul-Henning Kamp wrote: > In message , 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 to lock and unlock these them. > That would go a long way towards a "works if you're careful" > implementation. -- DE