8. (8) Consider the following parallel program: Novice: Apprentice: Expert for )
ID: 3596917 • Letter: 8
Question
8. (8) Consider the following parallel program: Novice: Apprentice: Expert for ) for ) for ) P (assemble) P (start) defect-defect +3 V (done) V (assemble) P (learn) printf ("defective-d ", P (done) P (assemble) defect defect +1 V (learn) P (alarm); defect-defect-2 V(start) V (assemble) defect) V (alarm) Suppose the initialization is: defect=2; alarm=1; start-done-assemble=learn-0. What is the output of the first 3 print statements? (a) (b) Suppose the initialization is defect=5; alarm=0; start-assemble=1 ; done=learn=0. What is the output of the first 3 print statements?Explanation / Answer
8)
a) defect=2
alarm=1
start=0
done=0
assemble=0
learn=0
Three infinte loops are running parallely.Since the first two loops
require assemble or done to be 1 to process furthur and both the variables
are zero. Hence, both the processes Novice and Apprentice are waiting.
Expert will run as alarm=1.
P(alarm) will make alarm=0 and defect=2-2=0 and still the other 2 processes
are waiting.
V(start) and V(assemble) will make start=1 and assemble=1.
Variables values after Expert execution.
defect=0
alarm=0
start=1
done=0
assemble=1
learn=0
Since alarm=0 Expert is also waiting now and Apprentice is waiting because done=0
Now, Novice will run
assemble=0 and start=0 after the first two lines execute.
defect=0+3=3 when next line execute.
done=1 , assemble=1 and learn=0 after execution of the next two lines.
Now Novice will wait as learn=0.
Variables values at this point.
defect=3
alarm=0
start=0
done=1
assemble=1
learn=0
Now Apprentice will run and done=0,assemble=0, defect=3+1=4
learn=1
Variables values at this point.
defect=4
alarm=0
start=0
done=0
assemble=0
learn=1
Now Apprentice will wait along with Expert and Novice will run from
the point where it switched .
learn=0
defective=4 will print
alarm=1
Variables values at this point.
defect=4
alarm=1
start=0
done=0
assemble=0
learn=0
Now again Expert will run and similar pattern as above will repeat.
defect=4-2=2
defect=2+3=5
defect=5+1=6
defective=6 will print
Next, defective=8 will print
Hence , the first 3 print statements are :
defective=4
defective=6
defective=8
8) b)
Similar analysis is required for this case
defect=5
defect=5+3=8
defect=8+1=9
defective=9 will print
defect=9-2=7
defect=7+3=10
defect=10+1=11
defective=11 will print
defect=11-2=9
defect=9+3=12
defect=12+1=13
defective=13 will print
defect=13-2=11
Hence , the first 3 print statements are :
defective=9
defective=11
defective=13
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.