Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 2013 17:12:43 +0000
From:      Orit Moskovich <oritm@mellanox.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        "freebsd-arch@freebsd.org" <freebsd-arch@freebsd.org>
Subject:   RE: FreeBSD spinlock - compatibility layer
Message-ID:  <981733489AB3BD4DB24B48340F53E0A55B0D4D32@MTLDAG01.mtl.com>
In-Reply-To: <201305221105.55093.jhb@freebsd.org>
References:  <981733489AB3BD4DB24B48340F53E0A55B0CFD79@MTLDAG01.mtl.com> <201305220859.32948.jhb@freebsd.org> <981733489AB3BD4DB24B48340F53E0A55B0D3CD8@MTLDAG01.mtl.com>, <201305221105.55093.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

Thanks, I appreciate all your help!

The section about the unbounded sleep wasn't included in the man page I've read so I wan't familiar with that concept...(http://www.unix.com/man-page/FreeBSD/9/locking/)



________________________________________
From: John Baldwin [jhb@freebsd.org]
Sent: Wednesday, May 22, 2013 6:17 PM
To: Orit Moskovich
Cc: freebsd-arch@freebsd.org
Subject: Re: FreeBSD spinlock - compatibility layer

On Wednesday, May 22, 2013 9:48:00 am Orit Moskovich wrote:
> From the mutex man page " By default, MTX_DEF mutexes will context switch
when they are already held."
> How is sleeping forbidden, but blocking on a mutex that might context switch
is ok?

Because they are different.  When you block on a lock you propragate your
priority to the lock holder and will resume execution if you are more
important as soon as the holder drops the lock.  In other words, you are going
to make forward progress.

With "event" sleeps like *sleep() and condition variables, there is no owner
to propagate priority to, and the sleep may very well be waiting for some
arbitrary event (such as the arrival of a network packet or completion of an
I/O request), so there is not the same guarantee of making forward progress.

The other half of this that keeps this true is that you are not permitted to
perform "event" sleeps while holding a mutex.  You have to drop the lock while
you wait which frees any threads waiting for the lock to run.  When you block
on a mutex the only thing you are ever waiting on is CPU time for either
yourself or the lock holder to run.

--
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?981733489AB3BD4DB24B48340F53E0A55B0D4D32>