libpthread patch

Terry Lambert tlambert2 at mindspring.com
Wed Apr 16 20:24:47 PDT 2003


Daniel Eischen wrote:
> On Thu, 17 Apr 2003, David Xu wrote:
> > Hmm,  I don't like to put malloc calling under critical section,
> > it is better to put it under a lock, otherwise this would cause dead
> > lock. suppose that an user thread is calling malloc(), and heap manager
> > got malloc spinlock, then it does somethings and the thread is preempted
> > by upcall from kernel,  now UTS switches to another thread, that thread
> > starts to call  pthread_create,  so UTS kernel enters a critical region first,
> > and calls malloc, this would cause dead lock, because UTS is under critical
> > region and no context switch could happen.
> 
> Hmm, I see what you mean.  We could put spinlock in critical region
> and that may solve the problem, but I eventually want to see spinlocks
> go away and replace the very few that we have in libc with mutexes.

Critical sectioning AND locking are a bad idea.  They are
orthogonal technologies which are intended to solve the same
basic problems.

You guys need to decide whether you are locking code paths or
if you are locking data objects.  Pick one and only one, and
stick with it consistently, or you will shoot your feet.

So far, the FreeBSD 5.0 locking has been pretty schitzophrenic.

-- Terry


More information about the freebsd-threads mailing list