🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.16k
Article #248

Re: Need word version of test-and-set

#248
From: Dave Mason
Date: Sun, 29 Dec 1985 00:18
29 lines
2297 bytes
In article <450@anasazi.UUCP> steve@anasazi.UUCP (Steve Villee) writes:
>> I am looking for a fast way to exit a critical section and see if anyone
>> else was waiting to get in.
>
>There is a way to do this on any processor that has a test-and-set primitive.
>The basic idea is to have a counter which is -1 if the resource is free, and
>otherwise the number of processes waiting to use the resource.  This counter
>is updated using ordinary (non-atomic) instructions, but access to it is gated
>via an outer gate using the test-and-set primitive.  You just spin on the outer
>gate until you get in, quickly examine and update the counter, and then open
>the outer gate.  If done properly, contention for the outer gate should be
>minimal, and there should be very little actual "spinning" on it.
>
The only problem is that I wanted to avoid spin-locks as the processes are
actually user-level timeshared processes, and if the holder of the lock
were to get swapped out, a lot of CPU time could be burned before it got
brought back in.  It appears that there isn't any way around it though, at
some level you've got to spin-lock, so I will do a system call if I don't
get the original lock (& do the spin-lock in the system where it's cheaper)
(I was going to have a system call to handle the queue anyway, it just has
to be a little more complicated than I had hoped.)
	Thanks
-- 
Usenet:	{dalcs dciem garfield musocs qucis sask titan trigraph ubc-vision
 	 utzoo watmath allegra cornell decvax decwrl ihnp4 uw-beaver}
	!utcsri!mason		Dave Mason, U. Toronto CSRI/ Ryerson Polytech
CSNET:	mason@Toronto
ARPA:	mason%Toronto@CSNet-Relay
BITNET:	FCTY7053@RYERSON.BITNET
Technical Details
Message-ID: <1866@utcsri.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utcsri!mason
References: <1813@utcsri.UUCP> <450@anasazi.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcsri!mason
From: mason@utcsri.UUCP (Dave Mason)
Newsgroups: net.micro.16k
Subject: Re: Need word version of test-and-set
Message-ID: <1866@utcsri.UUCP>
Date: Sat, 28-Dec-85 19:18:07 EST
Article-I.D.: utcsri.1866
Posted: Sat Dec 28 19:18:07 1985
Date-Received: Sat, 28-Dec-85 19:24:21 EST
References: <1813@utcsri.UUCP> <450@anasazi.UUCP>
Reply-To: mason@utcsri.UUCP (Dave Mason)
Organization: University of Toronto/Ryerson Polytechnic Institute
Lines: 29