Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Apr 2007 10:52:16 +0100 (BST)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Julian Elischer <julian@elischer.org>
Cc:        freebsd-hackers@freebsd.org, Hans Petter Selasky <hselasky@c2i.net>
Subject:   Re: msleep() on recursivly locked mutexes
Message-ID:  <20070428104944.U28395@fledge.watson.org>
In-Reply-To: <46311708.5030002@elischer.org>
References:  <200704262136.33196.hselasky@c2i.net> <46311708.5030002@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 26 Apr 2007, Julian Elischer wrote:

> Further the idea that holding a mutex "except for when we sleep" is a 
> generally bright idea is also a bit odd to me.. If you hold a mutex and 
> release it during sleep you probably should invalidate all assumptions you 
> made during the period before you slept as whatever you were protecting has 
> possibly been raped while you slept. I have seen too many instances where 
> people just called msleep and dropped the mutex they held, picked it up 
> again on wakeup, and then blithely continued on without checking what 
> happened while they were asleep.

And interesting observation here is that FreeBSD 4.x and earlier were actually 
rife with exactly this sort of race condition, exercised only when under 
kernel memory pressure because sleeping occurred only then.  The explicit 
locking model we use now makes these races larger due increased concurrency 
(preemption, parallelism, etc), but also makes our assertion model stronger.

Robert N M Watson
Computer Laboratory
University of Cambridge



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