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, (So, for a thread, a cycle is P, cr1, cr2, cr3, cr4, V, nc1, nc2, nc3, nc4, that takes a total of 1 + 1 + 1 + 2 = 5 ms. ) We now change the number of threads to 3 (three) (instead of 2). (a) Suppose OS schedules by round robin of thread 0 for 2ms, thread 1 for 2ms, thread 2 for 2 ms, thread 0 for 2ms, and thread 1 for 2ms, and thread 2 for 2 ms, and so on. This means we have TO, T1, T2, TO, T1, and T2, each for 2 ms. Compute the real amount of time when OS moves among these 3 threads twice as above.. (b) Show which instruction is being executed in thread 0 when thread 0, thread 1, and thread 2 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Processes and Threads
7.
1 System:
2
3 // create semaphore and initialize value to 1
4 Semaphore occupied = new Semaphore (1);
5
startThreads(); // initialize and launch both threads
6
7
8 Thread T
9
10 void main()
11 {
12 while (!done)
{
13
14
PC occupied ); // wait
// critical section code
15
16
17
18
19
20
21
22 } // Thread TX
V occupied ); // signal
// code outside critical section
} // end while
1
2
3
// create semaphore and initialize value to 1
4 Semaphore occupied = new Semaphore (1);
5
System:
6 startThreads(); // initialize and launch both threads
7
8 Thread T
9
10
11
12
13
14
15
16
17
18
19
void main()
{
while (!done)
{
PC occupied ); // wait
// critical section code
V occupied ); // signal
// code outside critical section
} // end while
20
21
22 } // Thread TX
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,
(So, for a thread, a cycle is P, cr1, cr2, cr3, cr4, V, nc1, nc2, nc3, nc4, that takes a total of 1 + 1 + 1 + 2 = 5 ms. )
We now change the number of threads to 3 (three) (instead of 2).
(a) Suppose OS schedules by round robin of thread 0 for 2ms, thread 1 for 2ms, thread 2 for 2 ms, thread 0 for 2ms, and
thread 1 for 2ms, and thread 2 for 2 ms, and so on.
This means we have TO, T1, T2, T0, T1, and T2, each for 2 ms.
Compute the real amount of time when OS moves among these 3 threads twice as above..
(b) Show which instruction is being executed in thread 0 when thread 0, thread 1, and thread 2 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.
Notice. When there is just one semaphore, and thread 0 has executed P, but has NOT finished executing V, then thread 1,
can execute P, but can NOT execute cr1, cr2, etc.
This is just like when you go to the restroom and somebody is inside, you can NOT use it
Transcribed Image Text:Processes and Threads 7. 1 System: 2 3 // create semaphore and initialize value to 1 4 Semaphore occupied = new Semaphore (1); 5 startThreads(); // initialize and launch both threads 6 7 8 Thread T 9 10 void main() 11 { 12 while (!done) { 13 14 PC occupied ); // wait // critical section code 15 16 17 18 19 20 21 22 } // Thread TX V occupied ); // signal // code outside critical section } // end while 1 2 3 // create semaphore and initialize value to 1 4 Semaphore occupied = new Semaphore (1); 5 System: 6 startThreads(); // initialize and launch both threads 7 8 Thread T 9 10 11 12 13 14 15 16 17 18 19 void main() { while (!done) { PC occupied ); // wait // critical section code V occupied ); // signal // code outside critical section } // end while 20 21 22 } // Thread TX 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, (So, for a thread, a cycle is P, cr1, cr2, cr3, cr4, V, nc1, nc2, nc3, nc4, that takes a total of 1 + 1 + 1 + 2 = 5 ms. ) We now change the number of threads to 3 (three) (instead of 2). (a) Suppose OS schedules by round robin of thread 0 for 2ms, thread 1 for 2ms, thread 2 for 2 ms, thread 0 for 2ms, and thread 1 for 2ms, and thread 2 for 2 ms, and so on. This means we have TO, T1, T2, T0, T1, and T2, each for 2 ms. Compute the real amount of time when OS moves among these 3 threads twice as above.. (b) Show which instruction is being executed in thread 0 when thread 0, thread 1, and thread 2 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. Notice. When there is just one semaphore, and thread 0 has executed P, but has NOT finished executing V, then thread 1, can execute P, but can NOT execute cr1, cr2, etc. This is just like when you go to the restroom and somebody is inside, you can NOT use it
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY