Page  ofGA22-7000-4   Revised  September  1,  1975  
By TNL: GN22-0498SRR   UPDATE   Routine  
Initial conditions:
General register (GR) 2 contains the address of the word
to beupdated.   L  3,0(2)   FETCH  THE  WORD   TRY  AGN  LR  4,3  MOVE   IT  TO   GR4  
[ANYINSTRUCTION]   MODIFY   GR4  (e.g.,  add  a  constant,  
set a bit, etc.)CS   BNE  
3,4,0(2)STORE   THE  NEW  VALUE   IF  THE  WORD   HAS   NOT   CHANGED  
TRYAGN
The branch toTRY   AGN  is  different  from  "bit-spinning"   in  that  the  branch  will  be  taken  only  if  some  other  program  modifies   the  update  location.  If  a  number  of  CPUs   simul  
taneously attempt to modify one location, oneCPU   will  
fall through the loop, another will loop once, and so on until
allCPUs   have  succeeded.  
BypassingPOST   The  following  routine  allows  the  SVC   "POST"   as  used  in  OS/VS   to  be  bypassed  whenever  the  corresponding  WAIT  
has not yet been issued, provided that the supervisor WAIT
andPOST   routines  use  COMPARE   AND  SWAP  to  manipu  
late event control blocks(ECBs).   BYPASS   POST   Routine  
Initial conditions:
GRl contains the address of theECB.   GRO   contains  the  POST   code.  HSPOST   L  3,0(1)   GR3  =  CONTENTS   OF   ECB  
LTR 3,3 ECB MARKED 'WAITING'
BMPSVC   YES,   ISSUE   AN  SVC   CS   3,0,0(1)   NO,   STORE   POST   CODE   BE  EXIT  CONTINUE   PSVC   SVC   POST   ECB  ADDRESS   IS   IN  GRl,  POST   CODE   IN  GRO   EXIT  [ANY  INSTRUCTION]   A  corresponding  bypass  WAIT  function,  using  TM,  is  in  
use at present.
The following routine may beused   in  place  of  the  previous  HSPOST   routine  if  the  ECB   is  assumed  to  contain  zeros  
when it is not"WAITING."   HSPOST   SR   0,0   CS   0,2,0(1)   BE  EXIT  SVC   POST   EXIT  [ANY  INSTRUCTION]   Lock/Unlock   When  SRRs  larger  than  a  doubleword  are  to  be  updated,  it  
is usually necessary to provide special interlocks to ensure
312System/370   Principles  of  Operation  
that a single program at a time updates the SRR. In general,
updating a list, or even scanning a list, cannot be safely
accomplished without first"freezing"   the  list.  However,  
theCOMPARE   AND  SWAP   instructions  can  be  used  in  
certain restricted situations to perform queuing and list
manipulation.Of   prime  importance  is  the  capability  to  per  
form the lock/unlock functions and to provide sufficient
queuing to resolve contentions, either in aLIFO   or  FIFO   manner.  The  lock/unlock  functions  can  then  be  used  as  the  
interlock mechanism for updating anSRR   of  any  complexity.  
The lock/unlock functions are based on the use of a header
associated with the SRR. The header is the common starting
point for determining the states of the SRR, either free or
in use, and is also used for queuing requests when con
tentions occur.Contentions   are  resolved  using  WAIT  and  POST.   Although  the  examples  do  not  show  it,  it  is  expected  
that theBYPASS   WAIT  and  BYPASS   POST   would  be  used.  
The general programming technique requires that the pro
gram that encounters a lockedSRR   must  "leave   a  mark  on  
thewall"   indicating  the  address  of  an  ECB   on  which  it  will  
WAIT. The program"unlocking"   sees  the  mark  and  posts  
theECB,   thus  permitting  the  waiting  program  to  continue.  
In the two examples given, all programs using a particularSRR   must  use  either  the  LIFO   queuing  scheme  or  the  FIFO   scheme;  the  two  cannot  be  mixed.  When  more  complex  
queuing is required, it is suggested that the queue for theSRR   be  locked  using  one  of  the  two  methods  shown.  Lock/Unlock   with  LIFO   Queuing  for  Contentions  
The header consists of a word, which can contain zero, a
positive value, or a negative value.•   A  zero  value  indicates  that  the  SRR   is  free.  •   A  negative  value  indicates  that  the  SRR   is  in  use  but  no  
additional programs are waiting for the SRR.•   A  positive  value  indicates  that  the  SRR   is  in  use  and  that  
one or more additional programs are waiting for the SRR.
Each waiting program is identified by an element in a
chained list. The positive value in the header is the address
of the element most recently added to the list..   Each  element  consists  of  two  words.  The  first  word  is  used  
as anECB;   the  second  word  is  used  as  a  pointer  to  the  next  
element in the list. A negative value in a pointer indicates
that the element is the last element in the list. The element
is required only if the program finds theSRR   locked  and  
desires to be placed in the list.
The following char
f.   scribes   the  action  taken  for  LIFO   LOCK   and  LIFO   UNLOCK   routines.  
By TNL: GN22-0498
Initial conditions:
General register (GR) 2 contains the address of the word
to be
[ANY
set a bit, etc.)
3,4,0(2)
TRYAGN
The branch to
taneously attempt to modify one location, one
fall through the loop, another will loop once, and so on until
all
Bypassing
has not yet been issued, provided that the supervisor WAIT
and
late event control blocks
Initial conditions:
GRl contains the address of the
LTR 3,3 ECB MARKED 'WAITING'
BM
use at present.
The following routine may be
when it is not
is usually necessary to provide special interlocks to ensure
312
that a single program at a time updates the SRR. In general,
updating a list, or even scanning a list, cannot be safely
accomplished without first
the
certain restricted situations to perform queuing and list
manipulation.
form the lock/unlock functions and to provide sufficient
queuing to resolve contentions, either in a
interlock mechanism for updating an
The lock/unlock functions are based on the use of a header
associated with the SRR. The header is the common starting
point for determining the states of the SRR, either free or
in use, and is also used for queuing requests when con
tentions occur.
that the
The general programming technique requires that the pro
gram that encounters a locked
the
WAIT. The program
the
In the two examples given, all programs using a particular
queuing is required, it is suggested that the queue for the
The header consists of a word, which can contain zero, a
positive value, or a negative value.
additional programs are waiting for the SRR.
one or more additional programs are waiting for the SRR.
Each waiting program is identified by an element in a
chained list. The positive value in the header is the address
of the element most recently added to the list.
as an
element in the list. A negative value in a pointer indicates
that the element is the last element in the list. The element
is required only if the program finds the
desires to be placed in the list.
The following char
f
            
            







































































































































































































































































































































