Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Aug 2007 12:51:58 -0700
From:      John-Mark Gurney <gurney_j@resnet.uoregon.edu>
To:        Roman Divacky <rdivacky@freebsd.org>
Cc:        hackers@freebsd.org
Subject:   Re: strange KASSERT in _sleep()
Message-ID:  <20070811195158.GY99491@funkthat.com>
In-Reply-To: <20070811124612.GA21695@freebsd.org>
References:  <20070811124612.GA21695@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Roman Divacky wrote this message on Sat, Aug 11, 2007 at 14:46 +0200:
> tsleep() maps to _sleep() with lock = NULL,
> 
> the _sleep() contains this:
> 
>   KASSERT(timo != 0 || mtx_owned(&Giant) || lock != NULL ||
>               ident == &lbolt, ("sleeping without a lock"));
> 
> 
> which simplifies for tsleep(foo, ...) where foo != lbolt to
> "timo != 0 || mtx_owned(&Giant)"
> 
> why do I have to hold Giant or have timo != 0 when calling tsleep?

To prevent a deadlock..  It would be possible for you to miss your
wakeup if you don't have a lock (such as Giant) held...  By forcing
a timeout, you guarantee that it will check the condition sometime
in the future...

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."



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