libpthread patch

Daniel Eischen eischen at pcnet1.pcnet.com
Wed Apr 16 22:43:39 PDT 2003


On Wed, 16 Apr 2003, Terry Lambert wrote:

> 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.

The critical section is to prevent the thread from being
swapped out by the kernel and sent to another KSE.  That's
it; it's not meant to do the same thing as locking.
There's per-kse stuff that needs to be accessed that
isn't correct if the thread gets run on another KSE,
regardless of whether or not a lock protects it.

If it wasn't possible for the kernel to send completed
threads from one KSE to another (within the same KSE
group), we probably wouldn't need critical sections
(at least as currently implemented).

-- 
Dan Eischen



More information about the freebsd-threads mailing list