Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Mar 2005 10:14:21 -0500 (EST)
From:      Daniel Eischen <deischen@freebsd.org>
To:        Andriy Tkachuk <andrit@ukr.net>
Cc:        David Xu <davidxu@freebsd.org>
Subject:    Re: patch for threads/76690 - critical - fork hang in child for-lc_r
Message-ID:  <Pine.GSO.4.43.0503031008130.2058-201000@sea.ntplx.net>
In-Reply-To: <012901c51fd3$131e23b0$090210ac@BORJA>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
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

[-- Attachment #2 --]
diff -r -u lib/libc_r/uthread/uthread_fork.c lib.patched/libc_r/uthread/uthread_fork.c
--- lib/libc_r/uthread/uthread_fork.c	Fri Dec 10 09:06:45 2004
+++ lib.patched/libc_r/uthread/uthread_fork.c	Thu Mar  3 14:50:06 2005
@@ -68,8 +68,15 @@
 			af->prepare();
 	}
 
+	extern spinlock_t *__malloc_lock;
+	if (__isthreaded && __malloc_lock != NULL)
+		_SPINLOCK(__malloc_lock);
+
 	/* Fork a new process: */
 	if ((ret = __sys_fork()) != 0) {
+		if (__isthreaded && __malloc_lock != NULL)
+			_SPINUNLOCK(__malloc_lock);
+
 		/* Run down atfork parent handlers. */
 		TAILQ_FOREACH(af, &_atfork_list, qe) {
 			if (af->parent != NULL)
@@ -78,6 +85,9 @@
 		_pthread_mutex_unlock(&_atfork_mutex);
 
 	} else {
+		if (__isthreaded && __malloc_lock != NULL)
+			_SPINUNLOCK(__malloc_lock);
+
 		/* Close the pthread kernel pipe: */
 		__sys_close(_thread_kern_pipe[0]);
 		__sys_close(_thread_kern_pipe[1]);

[-- Attachment #3 --]
_______________________________________________
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"
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.43.0503031008130.2058-201000>