I don't think there is an easy answer to before or after. It depends on the
particular logic. I have been writing assembler code for (literally!) fifty
years and I have to pause and think and think and think every time about
code like this.

You need to take a pencil and put a little line between every two
instructions and say "if I get interrupted here, and all this other code
runs while one thread is between these two instructions, what happens?" And
do that for every two instructions. Further, if you could get interrupted by
another processor (which is almost certainly the case) you have to do the
same thing for every *individual* instruction that is *not* atomic (LM/STM,
MVC, etc.).

Charles


-----Original Message-----
From: IBM Mainframe Assembler List [mailto:[email protected]]
On Behalf Of [email protected]
Sent: Monday, July 29, 2019 10:45 AM
To: [email protected]
Subject: Circular Queue Handling in Assembler

Hi,
.
I have a program which obtains a Memory Chunk, which is carved into a queue
of  256
byte fixed length entries.  I could have used a Data space.
.
In 31 Bit storage is the control information for the 64Bit Memory Chunk
queue.
The 31 Bit storage control structure has the beginning address of the Memory
Chunk, the Ending Address Of the Memory Chunk, the number of fixed length
entries
an Ordinal Number (INDEX) and some state data. 
.
The ordinal Number is used to index into the Memory Chunk of fixed length
entries
(queue) and is incremented using Compare and Swap (CS). 
The program never searches the queue to find an available slot - it always
appends to the next  entry by incrementing the ordinal number using compare
and swap..  
.
The memory chunk is used as a circular queue, meaning, when we reach the end
of
the queue (memory chunk), we resume by re-using the first entry at the top
of the queue
(wrap around).
We all-ways add new/next entries by incrementing the ordinal number and
indexing
into our Memory Chunk.
.
Here's My concern -
When we reach the end of the queue - the program needs to reset ther Ordinal
Index back to 0.
(so we can continue to add the next entry at the beginning of the queue)..
Is it better to test/reset this Index number before or after adding the last
entry in the queue ?Should there be a second Compare and Swap ?
.
.
Paul 
* 
.

Reply via email to