Article View: bit.listserv.asm370
Article #1550Re: Strange use of compare-and-swap
From: Jim Blalock
Date: Thu, 25 Jun 1992 20:14
Date: Thu, 25 Jun 1992 20:14
38 lines
2379 bytes
2379 bytes
On Thu, 25 Jun 1992 16:34:04 GMT Alasdair Grant said:
> I'm working on an old piece of code (a GATE task, so the author wasn't
> dumb!) and see the following:
>
> LABEL XR 0,0
> L 1,COUNTER
> CS 1,0,COUNTER
> BNZ LABEL
>
> Now COUNTER is incremented and decremented by CS's elsewhere, which is
> necessary in this case. But surely just storing a value into a fullword
> (aligned) doesn't require CS. Can someone reassure me that replacing this
> by a single ST is ok under all circumstances, and that this idiom (which
> is used many times in the program) is false paranoia?
Compare-and-swap (if I can remember without looking it up) does the
following:
"CS Rx,Ry,fullword": Serialize memory access
If Rx = fullword
Store Ry at fullword
Set "Z" condition code
Else
Set "NZ" condition code
Endif.
There are two handy things here. The first is that CS will "serialize
memory access". CS will lock out memory access from other processors
(and channels, I think) while it is running. It's commonly used when
queue anchors and other things that are used by multiple tasks need to
be changed with no chance of concurrent update on a multiple-engine box.
The other is that CS does all this in one instruction, which means that
the operating system can't take control away from you and dispatch
someone else, like it can between a LOAD and a STORE.
If there's a chance that multiple task threads could be executing this
code against the same storage at the same time, I'd leave the CS's in.
Anyway, if it works, why fix it?
Technical Details
Message-ID:
<ASM370%92062516134810@UGA.CC.UGA.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!auvm!CLEMSON.BITNET!CAREYShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcdcb,97471b04c882180b,start X-Google-Attributes: gidfcdcb,public X-Google-ArrivalTime: 1992-06-25 00:07:02 PST Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU Path: arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!auvm!CLEMSON.BITNET!CAREY Message-ID: <ASM370%92062516134810@UGA.CC.UGA.EDU> Newsgroups: bit.listserv.asm370 Date: Thu, 25 Jun 1992 16:14:00 EDT Sender: IBM 370 Assembly Programming Discussion List <ASM370@UGA.BITNET> From: Jim Blalock <CAREY@CLEMSON.BITNET> Subject: Re: Strange use of compare-and-swap Lines: 38