This solution works to synchronise two processes. It assumes that the and
instructions are atomic and cannot
be interrupted.
The two processes in question share two variables:
| (4) |
The processes may either interfere with each other, or not interfere:
This solution may not work in modern systems, since they can reorder instructions which are not dependent on each other to improve efficiency. This may result in an unexpected order of instructions, and therefore unexpected behaviour with this approach.
A fix to this is to use a Memory Barrier, when used, the system will then ensure that all
and
instructions are completed before proceeding, effectively ensuring the order or instructions will be
followed as intended.