threads/76690: fork hang in child for (-lc_r & -lthr)

Sven Berkvens-Matthijsse sven at ilse.net
Tue Oct 25 00:16:26 PDT 2005


> > But then the free() in the child process may be using an unstable
> > state of the malloc system (because if you don't acquire the lock
> > before the fork(), malloc() may be busy in the middle of the
> > fork()).
> 
> I don't think that can happen because libc_r will not switch out a
> thread that is in a critical region (and libc locks are critical
> regions) until it leaves the region.

What code leads you to that conclusion? All the malloc functions
simply lock a spinlock, do their work, and then unlock the spinlock.
If the code gets interrupted by a timer signal and the thread
scheduler schedules a thread that calls fork(), the malloc system will
be in an unstable state in the child process, and when the thread
library calls free() itself, the spinlock will already be locked,
causing free() to hang. If you decide to set __isthreaded to 0, free()
will be manipulating data that was in the process of being manipulated
by the parent process (and is now in a potentially unusable state).

> -- 
> DE

-- 
Sven


More information about the freebsd-threads mailing list