The Basics:-
As per your question:-
just name them
1. x=1
2. y = y+x
3. y=2
4. x=x+3
let A: begin: 1,2, end
let B: begin: 3,4, end
Finally your question is
Co-begin:
A
B
Co-end:
How many orders possible? ( just go with the formula in DBMS, Concurrent Transaction )
total order = $\frac{(2+2)!}{2! . 2!} = \frac{(4)!}{4} = 6 $
what are they:-
(i) 1,2,3,4
(ii) 1,3,2,4
(iii) 1,3,4,2
(iv) 3,4,1,2
(v) 3,1,4,2
(vi) 3,1,2,4
DBMS vs OS :-
in DBMS, these (1,2,3,4) are transactions, those are atomic operations in a Transactions
but in Os, these(1,2,3,4) are instructions, those are atomic or non-atomic
What are the possibilities of output if those are atomic instructions?
Directly, you can execute every order.
(i) 1,2,3,4 ===> lead to final output : x= 4, y=2
(ii) 1,3,2,4 ===> lead to final output : x= 4, y=3
(iii) 1,3,4,2 ===> lead to final output : x= 4, y=6
(iv) 3,4,1,2 ===> lead to final output : x= 1, y=3
(v) 3,1,4,2 ===> lead to final output : x= 4, y=6
(vi) 3,1,2,4 ===> lead to final output : x= 4, y=3
What are the possibilities of output if those are non-atomic instructions ?
you have think the instruction is like ( load, increment, store )
all the 6 possibilities also in this output, along with
x=4,y=1 when 1,2(load,increment,preempt),3,4,2(store)
x=3,y=5 when 2,4(load,store,preempt),1,4(store),2
x=3,y=3 when 2,4(load,store,preempt),1,2,4(store)
x=3,y=3 when 2,4(load,store,preempt),1,2,4(store)
(i hope i covered all possibilities, if you found more comment)