Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Apr 2003 01:43:36 -0400 (EDT)
From:      Daniel Eischen <eischen@pcnet1.pcnet.com>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: libpthread patch
Message-ID:  <Pine.GSO.4.10.10304170134240.5665-100000@pcnet1.pcnet.com>
In-Reply-To: <3E9E197A.6CD504E2@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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