Question
Assuming that P(occupied) and V(occupied) each takes 1 ms and critical section consists of 4 instructions cr1, cr2, cr3, and cr4 of equal instruction time
Assuming that P(occupied) and V(occupied) each takes 1 ms and critical section consists of 4 instructions cr1, cr2, cr3, and cr4 of equal instruction time adding up to 1 ms and noncritical section consists of 4 instructions nc1, nc2, nc3, and nc4 of equal instruction time adding up to 2 ms.
a) Suppose OS schedules by round robin of thread 0 for 2ms, thread 1 for 2ms, thread 0 for 2ms, and thread 1 for 2ms.
Compute the real amount of time when OS moves between thread 0 and thread 1 each twice as above. Note the amount of time could be more than 8 ms since at the end of 2 ms, thread 0 may be in the middle of an atomic instruction.
b) Show which instruction is being executed in thread 0 when thread 0 and thread 1 each has been executed twice with 2ms as the time of scheduling.
c) Tabulate and show how much time is spent in each instruction of thread 0 in the first run and in the second run.
l System. 2 3 I create semaphore and iniialize value Lo 4 Semaphore occupiednew SemaphoreCi) 6 startThreadsOinitialize and launch both threads 8 Thread 5 7 9 10 void main 1.2 13 14 15 16 1.7 18 19 20 21 whileC done PC occupied / wait critica1 section code VC occupied // signal /code outside critical section 1/ end while 22 /Thread TX l System. 2 3 I create semaphore and iniialize value Lo 4 Semaphore occupiednew SemaphoreCi) 6 startThreadsOinitialize and launch both threads 8 Thread 5 7 9 10 void main 1.2 13 14 15 16 1.7 18 19 20 21 whileC done PC occupied / wait critica1 section code VC occupied // signal /code outside critical section 1/ end while 22 /Thread TXStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started