This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

1. Parallelism and concurrency

Parallelism: The Parallelism of two processes, P and Q, running in the same order as PQPPQP, PPPQQP, QPQQPP, etc. With P | | Q P and Q as a set of parallel process.

Concurrency: There are two processes P and Q that run concurrently in a unified system, in no particular order. This is called a Concurrency process. They both belong to the traffic system and work at the same time, but their operation is in no order and does not interfere with each other. With P | | | Q P and Q as a set of concurrent processes.

2. Interlaced
T S TS
(Interleaving of Transition Systems)

1. Definition of TSTSTS TSi = (Si, Acti – I, Ii, APi, Li), I = 1, 2 TS_ {I} = (S_ {I}, Act_ {I}, \ to_ {I}, I_ {I}, AP_ {I}, L_ {I}), I = 1, 2, TSi = (Si, Acti – I, Ii, APi, Li), I = 1, 2

2. TSTSTS concurrent expression: TS1TS_ {1} TS1 | | | TS2 = (S1) S2, Act1 ∪ Act2, – >, I1 x I2, AP1 ∪ AP2, L) TS_ {2} = (S_ {1} \ times S_ {2}, Act_ {1} \ CPU Act_ {2}, \ to, I_ {1} AP_ \ times I_ {2}, {1} \ CPU AP_ {2}, L) TS2 = (S1) S2, Act1 ∪ Act2, – >, I1 x I2, AP1 ∪ AP2, L), the transfer relationship – \ to – define rules for: S1 – > 1 alpha S1 ‘⟨ S1, S2 ⟩ – alpha ⟨’ S1 and S2 ⟩ \ tfrac {S_ {1} \ overset {\ alpha} {\ rightarrow_ {1}} {S_}} {{1} ‘\ langle S_ {1}, S_ {2} \ rangle \ overset {\ alpha} {\ rightarrow} \ langle {S_ {1}} ‘, S_ {2} \ rangle} ⟨ S1, S2 ⟩ – alpha ⟨ ‘S1 and S2 ⟩ alpha S1’ and S1 – > 1 Alpha S2 S2-2 ‘⟨ S1, S2 ⟩ – alpha ⟨ S1, S2’ ⟩ \ tfrac {S_ {2} \ overset {\ alpha} {\ rightarrow_ {2}} {S_}} {{2} ‘\ langle S_ {1}, S_ {2} \ rangle \ overset {\ alpha} {\ rightarrow} \ langle S_ {1}, {S_ {2}} ‘\ rangle} ⟨ S1, S2 ⟩ – alpha ⟨ S1, S2’ ⟩ alpha S2 S2-2 ‘

Tag function name ‘LLL define rules for: L (⟨ s1, s2 ⟩) = L (s1) ∪ L (s2) L (\ langle s_ {1}, s_ {2} \ rangle) = L (s_ {1}) \ cup L (s_ {2}) L (⟨ s1, s2 ⟩) = L (s1) ∪ L (s2)

3. Sample:

  • Activity α\alphaα means x:=x+1x:=x+1x:=x+1

activity
Beta. \beta
said
y : = y 2 y:=y-2
Initial conditions:
x = 0 . y = 7 x=0,y=7
then
Alpha. Beta. \alpha ||| \beta
The process is shown in the figure below:(The figure on the right shows the execution of any activity at a time, starting from the initial state
Alpha. \alpha
and
Beta. \beta
Each execution once)

  • However, if two activities share a variable, modifying the same variable can result in error conditions, such as:

activity
Alpha. \alpha
said
x : = 2 x x:=2\cdot x
activity
Beta. \beta
said
x : = x + 1 x:=x+1
Initial conditions:
x = 3 x=3
then
Alpha. Beta. \alpha ||| \beta
The process is shown in the figure below:(At this point, the model established by TS will lead to contradictory results of shared variables: different values of shared variables in the same state, and incorrect execution results)

3. The interlaced
P G PG
(Interleaving of Program Graphs)

1. Definition: PGi = (Loci which, Acti, Effecti ↪ I, Loc0, I, g0, I), I = 1, 2 PG_ {I} = (Loc_ {I}, Act_ {I}, Effect_ {I}, \ hookrightarrow_ {I}. I is Loc_ {0}, g_ {0, I}), I = 1, 2, PGi = (Loci which, Acti, Effecti ↪ I, Loc0, I, g0, I), I = 1, 2, is a variable VariVar_ {I} Vari two PG, Then, at Var1∪Var2Var_{1} \cup Var_{2}Var1∪Var2, Have PG1 ∣ ∣ ∣ PG2 = (Loc1 x Loc2, Act1 ⊎ Act2, Effect, ↪, Loc0, 1, Loc0, 2, g0, 1 Sunday afternoon g0, 2) PG_ {1} | | | PG_ {2} = (Loc_ {1} \ times Loc_ {2}, Act_ {1} \ uplus Act_ {2}, Effect, \ hookrightarrow_, Loc_ {0, 1}, Loc_} {0, 2, g_ {0, 1} \ wedge g_ {0, 2}) PG1 ∣ ∣ ∣ PG2 = (Loc1 x Loc2, Act1 ⊎ Act2, Effect, ↪, Loc0, 1, Loc0, 2, g0, 1 Sunday afternoon g0, 2)

  • Transfer relationship ↪\ HookRightarrow ↪ Defines the rules as:
  • The effect set EffectEffectEffect defines the rules as follows: Effect (alpha, eta) = Effecti (alpha, eta) if alpha ∈ ActiEffect (eta), alpha, and = Effect_ {I} (eta) \ alpha, \ \ \ if \ \ alpha \ in Act_ {I} Effect (alpha, eta) = Effecti (alpha, eta) if alpha ∈ Acti

\quad means that the new EffectEffectEffect table is taken from the previous two EffectEffectEffect tables, and the action α\alphaα performed on the current transfer is in which PG action (ActiAct_iActi), Just use the corresponding EffectiEffect_iEffecti action α\alphaα to transform the assignment η\etaη.

Example 1: x = x + 1 ∣ ∣ ∣ x: xx = x + 1 = 2 ⋅ | | | x: xx = x + 1 = 2 \ cdot ∣ ∣ ∣ x: ⋅ x = 2

  • PG modeling

  • Model of alternating

  • Transform the interleaved PG model into a TS model

At this point, the result is that the two processes interleaved correctly, and the value of the final variable depends on the execution order of the two critical sections of the code.

3. Program modeling with mutex semaphore

  • Definition: there is a shared variable y with an initial value of 1; When y is 1, the mutex is free and can be occupied and accessed. When y is 0, the mutex is locked and cannot be occupied or accessed.
  • Example:

At first,
P G 1 PG_1
and
P G 2 PG_2
Are in the non-critical region (
n o n c r i t i noncrit_i
), then enter the holding area; In the waiting area, it will judge whether the conditions are met:
y > 0 y>0
If the condition is met, it will be executed
y : = y 1 y:=y-1
, the critical area is locked, indicating that the critical area is in use and other PG cannot enter the critical area. Then the PG enters the critical area and performs corresponding operations. Execute after performing operations in critical sections
y : = y + 1 y:=y+1
, unlock the critical area and return to the non-critical area. Other PGS can enter the critical area.
P G 1 P G 2 PG_1|||PG_2
The results of theTransform the results into a TS model
n 1 n_1
and
n 2 n_2
Represents a non-critical region
w 1 w_1
and
w 2 w_2
Represents the waiting area
c 1 c_1
and
c 2 c_2
Represents critical section resources, they do not appear at the same node at the same time, so avoid the conflict problem of critical section resources.

Peterson’s Mutual Exclusion algorithm

  • Shared variables: B1, B2,x,b_1,b_2,x, B1, B2,x,
  • Initial conditions: B1 = B2 = FALSEB_1 = B_2 = FALSEB1 = B2 =false

Process P1P_1P1:

loop forever 
... (*noncritical actions*)
 <b1 := true; x := 2;> 
 wait until (x = 1 ∨ ¬b2) 
 do critical section od 
 b1 := false 
 ... (*noncritical actions*)
 end loop
Copy the code

Process P2P_2P2:

loop forever 
... (*noncritical actions*)
 <b2 := true; x := 1;> 
 wait until (x = 2 ∨¬ b1) 
 do critical section od 
 b2 := false 
... (*noncritical actions*)
 end loop
Copy the code
  • process
    P 1 P_1
    and
    P 2 P_2
    the
    P G PG
    figure
  • TS (PG1 ∣ ∣ ∣ PG1TS (PG_1 | | | PG_1TS (PG1 ∣ ∣ ∣ PG1)