Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a system with two processors of unknown speed, the following two processes ru

ID: 3710157 • Letter: I

Question

In a system with two processors of unknown speed, the following two processes run in parallel. Assuming that each of the 10 instructions a - j is atomic, list eight different possible pairs of sequence with the outcomes (for x, y) that can be produced by this code fragment. Show each sequence and outcome.

The shared variables x is initialized to 1, y initialized to 0 and the shared semaphore mutex has initial value 1.

Index

Process 1

Index

Process 2

a)

x =x*3

f)

y=5+x

b)

Semwait(mutex)

g)

Semwait(mutex)

c)

y = 2 * x

h)

y = y -1

d)

x =y- 2

i)

x = x+y

e)

Semsignal(mutex)

j)

Semsignal(mutex)

Index

Process 1

Index

Process 2

a)

x =x*3

f)

y=5+x

b)

Semwait(mutex)

g)

Semwait(mutex)

c)

y = 2 * x

h)

y = y -1

d)

x =y- 2

i)

x = x+y

e)

Semsignal(mutex)

j)

Semsignal(mutex)

Explanation / Answer

Following are the 8 possible pairs. There can be many -

1)

Instruction (a) : x=x*3 i.e x=3

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=6

Instruction (d) : x=y-2 i.e x=4

Instruction (e) : Mutex value will be 1 i.e Mutex=1

Instruction (f) : y=5+x i.e y=9

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=8

Instruction (i) : x=x+y i.e. x=12

Instruction (j) : Mutex value will be 1 i.e Mutex=1

Therefore, Output x = 12, y = 8.

2)

Instruction (f) : y=5+x i.e y=6

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=5

Instruction (i) : x=x+y i.e. x=6

Instruction (j) : Mutex value will be 1 i.e Mutex=1

Instruction (a) : x=x*3 i.e x=18

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=36

Instruction (d) : x=y-2 i.e x=34

Instruction (e) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 34, y = 36.

3)

Instruction (a) : x=x*3 i.e x=3

Instruction (f) : y=5+x i.e y=8

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=6

Instruction (d) : x=y-2 i.e x=4

Instruction (e) : Mutex value will be 1 i.e Mutex=1

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=5

Instruction (i) : x=x+y i.e. x=9

Instruction (j) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 5, y = 9.

4)

Instruction (f) : y=5+x i.e y=6

Instruction (a) : x=x*3 i.e x=18

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=5

Instruction (i) : x=x+y i.e. x=23

Instruction (j) : Mutex value will be 1 i.e Mutex=1

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=46

Instruction (d) : x=y-2 i.e x=44

Instruction (e) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 44, y = 46.

5)

Instruction (a) : x=x*3 i.e x=3

Instruction (f) : y=5+x i.e y=8

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=7

Instruction (i) : x=x+y i.e. x=10

Instruction (j) : Mutex value will be 1 i.e Mutex=1

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=20

Instruction (d) : x=y-2 i.e x=18

Instruction (e) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 18, y = 20.

6)

Instruction (f) : y=5+x i.e y=6

Instruction (a) : x=x*3 i.e x=18

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=36

Instruction (d) : x=y-2 i.e x=34

Instruction (e) : Mutex value will be 1 i.e Mutex=1

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=35

Instruction (i) : x=x+y i.e. x=69

Instruction (j) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 69, y = 35.

7)

Instruction (a) : x=x*3 i.e x=3

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=6

Instruction (f) : y=5+x i.e y=9

Instruction (d) : x=y-2 i.e x=7

Instruction (e) : Mutex value will be 1 i.e Mutex=1

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=8

Instruction (i) : x=x+y i.e. x=15

Instruction (j) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 15, y = 8.

8)

Instruction (f) : y=5+x i.e y=6

Instruction (g) : Mutex value will be 0 i.e Mutex=0

Instruction (h) : y=y-1 i.e. y=5

Instruction (a) : x=x*3 i.e x=3

Instruction (i) : x=x+y i.e. x=8

Instruction (j) : Mutex value will be 1 i.e Mutex=1

Instruction (b) : Mutex value will be 0 i.e Mutex=0

Instruction (c) : y=2*x i.e y=16

Instruction (d) : x=y-2 i.e x=14

Instruction (e) : Mutex value will be 1 i.e Mutex=1


Therefore, Output x = 14, y = 16.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote