From owner-freebsd-threads@FreeBSD.ORG Thu Mar 3 15:14:23 2005 Return-Path: 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 1551116A4CE; Thu, 3 Mar 2005 15:14:23 +0000 (GMT) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id A471843D2D; Thu, 3 Mar 2005 15:14:22 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) j23FELbe006151; Thu, 3 Mar 2005 10:14:21 -0500 (EST) Date: Thu, 3 Mar 2005 10:14:21 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Andriy Tkachuk In-Reply-To: <012901c51fd3$131e23b0$090210ac@BORJA> Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/Mixed; BOUNDARY="----=_NextPart_000_0126_01C52001.298C64D0" Content-ID: X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) cc: threads@freebsd.org cc: David Xu Subject: Re: patch for threads/76690 - critical - fork hang in child for-lc_r X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 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 Mar 2005 15:14:23 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. ------=_NextPart_000_0126_01C52001.298C64D0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: On Thu, 3 Mar 2005, Andriy Tkachuk wrote: > > > > Hmm, libc_r and libpthread handle spinlock differently which malloc > > > > uses to protect itself, some real world benchmarks are better than > > this. > > yes , you right, David. one have to check __isthreaded before > firing _SPINLOCK. there will be nothing wrong, because > > static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; > > initialyzed regardless __isthreaded in malloc.c but > for optimization probably it is worth to add this check. > Take a look on updated patch. > > btw: i don't see the unlock in child in libpthread. there must be two > unlocks I told you in previous mail, _kse_single_thread() calls _thr_spinlock_init(). The malloc lock is not the only lock used in libc, so the safe way to make sure libc is in a clean state after a fork is to reinitialize all the locks used by libc, not just the malloc lock. libc really shouldn't try to use any locks unless __isthreaded is true, so after a fork() it shouldn't really matter what state the locks are in. -- DE ------=_NextPart_000_0126_01C52001.298C64D0 Content-Type: APPLICATION/OCTET-STREAM; NAME="libc_r-76690pr.patch2" Content-Transfer-Encoding: QUOTED-PRINTABLE Content-ID: Content-Description: Content-Disposition: ATTACHMENT; FILENAME="libc_r-76690pr.patch2" diff -r -u lib/libc_r/uthread/uthread_fork.c = lib.patched/libc_r/uthread/uthread_fork.c=0A= --- lib/libc_r/uthread/uthread_fork.c Fri Dec 10 09:06:45 2004=0A= +++ lib.patched/libc_r/uthread/uthread_fork.c Thu Mar 3 14:50:06 2005=0A= @@ -68,8 +68,15 @@=0A= af->prepare();=0A= }=0A= =0A= + extern spinlock_t *__malloc_lock;=0A= + if (__isthreaded && __malloc_lock !=3D NULL)=0A= + _SPINLOCK(__malloc_lock);=0A= +=0A= /* Fork a new process: */=0A= if ((ret =3D __sys_fork()) !=3D 0) {=0A= + if (__isthreaded && __malloc_lock !=3D NULL)=0A= + _SPINUNLOCK(__malloc_lock);=0A= +=0A= /* Run down atfork parent handlers. */=0A= TAILQ_FOREACH(af, &_atfork_list, qe) {=0A= if (af->parent !=3D NULL)=0A= @@ -78,6 +85,9 @@=0A= _pthread_mutex_unlock(&_atfork_mutex);=0A= =0A= } else {=0A= + if (__isthreaded && __malloc_lock !=3D NULL)=0A= + _SPINUNLOCK(__malloc_lock);=0A= +=0A= /* Close the pthread kernel pipe: */=0A= __sys_close(_thread_kern_pipe[0]);=0A= __sys_close(_thread_kern_pipe[1]);=0A= ------=_NextPart_000_0126_01C52001.298C64D0 Content-Type: TEXT/PLAIN; CHARSET=us-ascii Content-ID: Content-Description: Content-Disposition: INLINE _______________________________________________ freebsd-threads@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-threads To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" ------=_NextPart_000_0126_01C52001.298C64D0--