Race condition Gateway Tag Change Script — shared tag reads- memory tag

Two Gateway Tag Change Scripts fire simultaneously when the PLC changes shift:

PLC
 |
 |── Shift tag changes ──► Script A
 |                              writes memoryTag(Mtag1)
 |
 |── Machine status changes ──► Script B
                                    reads memoryTag(Mtag1)

The race

Both scripts fire at the same instant. Script B reads the memory tag before Script A has finished writing it.

Script A                    Script B
         
        |                           |
starts writing                  starts reading
memoryTag                       memoryTag
        |                           |
        |                    reads OLD value  ← stale
        |                           |
finishes writing             writes DB row
memoryTag (new value)        with OLD Mtag1 value

Script B gets the old value. The DB row is filed under the wrong production period.

Question

Is there a supported pattern to guarantee Script B reads the memory tag only after Script A has finished writing it?
Is there any better Approach to achieve it

Is it always sequential? Any reason not to start Script B after Script A in the same gateway script to completely sidestep having 2 scripts running at once?

Either that or use an intermediate tag that is both "script a has finished and machine status has changed"

Best practice is not to write to the same tag you are reading from, for the same reasons the OP is demonstrating.

saipeddireddy10, if you can tell us what you're trying to do, we can probably give you a better answer. nvm, I think I see what you're trying to do.
What are you writing with script A?

You will always have race possibilities like this since Ignition is highly multi-threaded and parallelized. The best way to ensure sequential behavior is to use just one script.

I wouldn't try to write the production period in the machine status script. Just write the new status and timestamp. The timestamp implicitly indicates the period when looked up later.