patch for threads/76690 - critical - fork hang in child for-lc_r

Andriy Tkachuk andrit at
Thu Mar 3 09:26:29 GMT 2005

> > > 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
- in child & in parent, doesn't it? :

# grep __malloc_lock -r libpthread
libpthread/thread/thr_fork.c:           _spinlock(__malloc_lock);
libpthread/thread/thr_fork.c:           if ((_kse_isthreaded() != 0) &&
(__malloc_lock != NULL)) {
libpthread/thread/thr_fork.c:                   _spinunlock(__malloc_lock);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libc_r-76690pr.patch2
Type: application/octet-stream
Size: 901 bytes
Desc: not available
Url :

More information about the freebsd-threads mailing list