From owner-freebsd-threads@FreeBSD.ORG Thu Aug 3 18:50:23 2006 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3BF6516A4DF for ; Thu, 3 Aug 2006 18:50:23 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED77E43D6E for ; Thu, 3 Aug 2006 18:50:18 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k73IoIh7014274 for ; Thu, 3 Aug 2006 18:50:18 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k73IoIBr014269; Thu, 3 Aug 2006 18:50:18 GMT (envelope-from gnats) Date: Thu, 3 Aug 2006 18:50:18 GMT Message-Id: <200608031850.k73IoIBr014269@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: "Poul-Henning Kamp" Cc: 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: Poul-Henning Kamp List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Aug 2006 18:50:23 -0000 The following reply was made to PR threads/101323; it has been noted by GNATS. From: "Poul-Henning Kamp" To: Daniel Eischen Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-threads@freebsd.org Subject: Re: threads/101323: fork(2) in threaded programs broken. Date: Thu, 03 Aug 2006 18:44:56 +0000 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 That would go a long way towards a "works if you're careful" implementation. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.