After loading the new index value, check if it's 256.  If so, do a
compare and swap for 255 to 0; if another process beat you to it, CS
fails and you have to reload the index value you now want (like 0 to 1),
just like you would if compare and swap fails.  The check for new index
= 255 has to be done in every loop.

Or, it more be more efficient to do as was suggested in another answer:
after loading the new index value, aNd the register with '000000FF'.

This may not be sufficient to protect the data being maintained in the
circular queue.  If my instance acquires index 42, for example, with the
above CS logic, there may be nothing to ensure that my instance actually
get the CPU cycles to move data to the associated 64-bit address before
the index is cycled by higher priority processes and some other instance
acquires index 42.

Gary

On 2019-07-29 2:32 p.m., Charles Mills wrote:
> 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
>
>
>
Gary Weinhold
Senior Application Architect
DATAKINETICS | Data Performance & Optimization
Phone:+1.613.523.5500 x216
Email: [email protected]
Visit us online at www.DKL.com
E-mail Notification: The information contained in this email and any 
attachments is confidential and may be subject to copyright or other 
intellectual property protection. If you are not the intended recipient, you 
are not authorized to use or disclose this information, and we request that you 
notify us by reply mail or telephone and delete the original message from your 
mail system.


-----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