From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 19 03:58:07 2009 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6293F106566C; Thu, 19 Mar 2009 03:58:07 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 47F208FC0C; Thu, 19 Mar 2009 03:58:07 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from apple.my.domain (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n2J3w2p6067519; Thu, 19 Mar 2009 03:58:03 GMT (envelope-from davidxu@freebsd.org) Message-ID: <49C1C356.9090006@freebsd.org> Date: Thu, 19 Mar 2009 12:00:22 +0800 From: David Xu User-Agent: Thunderbird 2.0.0.9 (X11/20080612) MIME-Version: 1.0 To: Kostik Belousov References: <4966F81C.3070406@elischer.org> <20090109163426.GC2825@green.homeunix.org> <49678BBC.8050306@elischer.org> <20090116211959.GA12007@green.homeunix.org> <49710BD6.7040705@FreeBSD.org> <20090120004135.GB12007@green.homeunix.org> <20090121230033.GC12007@green.homeunix.org> <20090122045637.GA61058@zim.MIT.EDU> <20090318163222.GE7716@deviant.kiev.zoral.com.ua> In-Reply-To: <20090318163222.GE7716@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , David Schultz , hackers@freebsd.org, Jason Evans , Julian Elischer Subject: Re: threaded, forked, rethreaded processes will deadlock X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2009 03:58:07 -0000 Kostik Belousov wrote: > I looked at the issue once more recently, and I propose the following > much less intrusive patch. It is somewhat hackish, but I think that > it would be good to have this working. Most other Unixes do have > working thread library after the fork. Any objections ? > > diff --git a/lib/libthr/thread/thr_fork.c b/lib/libthr/thread/thr_fork.c > index bc410d1..ae6b9ad 100644 > --- a/lib/libthr/thread/thr_fork.c > +++ b/lib/libthr/thread/thr_fork.c > @@ -173,14 +173,19 @@ _fork(void) > /* Ready to continue, unblock signals. */ > _thr_signal_unblock(curthread); > > - if (unlock_malloc) > + if (unlock_malloc) { > + __isthreaded = 1; > _malloc_postfork(); > + __isthreaded = 0; > + } > > /* Run down atfork child handlers. */ > TAILQ_FOREACH(af, &_thr_atfork_list, qe) { > if (af->child != NULL) > af->child(); > } > + > + THR_UMUTEX_UNLOCK(curthread, &_thr_atfork_lock); ^^^ This line is not needed. > } else { > /* Parent process */ > errsave = errno;