Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Sep 2000 08:29:39 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        bmilekic@technokratis.com (Bosko Milekic)
Cc:        freebsd-arch@FreeBSD.ORG
Subject:   Re: spinlocks and acquire pseudo-priority
Message-ID:  <200009280829.BAA11680@usr02.primenet.com>
In-Reply-To: <Pine.BSF.4.21.0009272218510.3246-100000@jehovah.technokratis.com> from "Bosko Milekic" at Sep 27, 2000 10:30:11 PM

next in thread | previous in thread | raw e-mail | index | archive | help
>   B continues to spin and eventually the
>   loop index reaches the "tolerated" values and there's a panic().
> 
>   	Please also note that even if B hits the top of the while loop and
>   decides that the mutex is no longer owned, so it hits the top of the
>   infinite loop and tries to grab it again, just before it grabs it, it
>   could already be had by C. This isn't TOO much of a problem, because the
>   probability is low, but grows with the number of processors. The problem
>   I see is that the index i is never reset to zero and may eventually hit
>   the tolerated values and trigger a panic.
> 
> 	Is there something I'm leaving out/forgetting?

You are talking about non-deadlock starvation here.

The simple answer is "use "for(;;)" instead of something with a
loop index".

The fact is, there is just as much probability of C losing a
race with B for a contended resource formerly held by A under
normal circumstances, as there is for it losing because of the
conditions which you describe.

The answer is: it doesn't matter -- you only ever use a spinlock
to do one of two things:

1)	Eat the overhead of a heavyweight non-spinning lock

2)	Contend a resource which will be available in a small
	amount of time anyway, so it doesn't matter whether
	you get it first or second

If you really cared about FIFO, FILO, or prioritization or some
other policy based ordering on lock acquisition, you would not
use spinlocks; you would use turnstiles and "wake one", or you
would use some other policy cognizant mechanism for doing the
granting.

FWIW, this means you wouldn't use a mutex, either.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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