P: abc Q: defa, b, c, d, e, f, are atomic actions. Each action has always the same effect independent of what other actions may be executing at the same time.
abcdef abdcef abdecf abdefc adbcef ...... defabcThat is, the actions of the two activities are sequenced in all possible ways that preserve the order in which the actions appeared in the two activities.
The inportance of the concept of interleaving is that it allows us to determine the meaning of concurrent programs.
Since the parallel execution of activities is equivalent to the sequential execution of an interleaving of these activities, it can complete with different results. We will say that a set of activities (i.e. a program) is DETERMINATE if any time it runs, for the same inputs, it gives the same outputs. Otherwise it is NON-DETERMINATE (it has a RACE CONDITION).
Here are two activities that are not determinate. The first activity just executes the assignment a := 1; The second activity just executes the assignment a := 2;
Supposed that you are given the following two activities P and Q:
P: x := 2; Q: x := 3; y := x - 1; y := x + 1;What are the possible results of the parallel execution of these two activities? [Answer: x=3 and y=4, or x=2 and y=1, or x=2 and y=3, or x=3 and y=2. If you do not want to get some of these results, then you have to prevent the occurrence of the interleavings that caused those results. This is done with SYNCHRONIZATION MECHANISMS.]
The BERNSTEIN CONDITIONS are used to determine if a program is determinate.
The READ SET and the WRITE SET of an action A are respectively the set of
variables read by A and written by A. The Read Set of an activity P, R(P),
is the union of the read sets of all the actions of P. Similarly, the Write Set
of P, W(P), is the union of the write sets of all the actions of P.
For example, if P is:
x := u + v; y := x * w;then R(P) = {u,v,x,w}, W(P) = {x, y}. Notice that x is both in R(P) and in W(P).
If these conditions are not satisfied, then it is possible that the parallel execution of P and Q is determinate [can you come up with an example?], but usually it is not.
The Bernstein Conditions are informative but too demanding: in most situations we want to execute activities that read/write the same data, and yet we don't want to give up determinacy. Thus something else is needed, some way of limiting the interleavings that are possible when executing activities in parallel. That is what SYNCHRONIZATION MECHANISMS do for us.
ingargiola.cis.temple.edu