Happens-before constraint
We established in the previous section that context switches are not predictable; there is uncertainty about the time at which they are likely to occur in our programs. Despite that, there is certainty about the instructions that are being executed concurrently.
Let's continue with a simple example. To start with, we're going to work on the basis that we've got a task like the one you see next in Code Box 13-1, which has five instructions. Note that these instructions are abstract, and they don't represent any real instructions like C or machine instructions:
Task P { 1. num = 5 2. num++ 3. num = num – 2 4. x = 10 5. num = num + x }
Code Box 13-1: A simple task with 5 instructions
As you can see, the instructions are ordered, which means that they must be executed in that specified order in order to satisfy the purpose of the task. We are certain about this. In technical terms, we say that we have...