Tutorial3

Tutorial3 - problem for two threads. Argue for its...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Tutorial III October 25, 2010 Question 1 (2007/08 Examination) Assume all the processes in a process set arrive at time 0 in the following order: P1, P2, P3, P4, P5, P6 The table below shows the CPU burst time and priority (with a smaller number implies a higher priority) for each process. Process CPU Burst Time Priority P1 8 1 P2 2 3 P3 3 6 P4 1 5 P5 6 4 P6 4 2 i. Draw a timeline diagram for each of the following scheduling algorithms: FIFO, SPF, non-preemptive priority, and RR with quantum = 2. Assuming context switching overhead is negligible. ii. Compute the average waiting time and average normalized turnaround time for each scheduling algorithm and determine which one gives the worst results. Question 2 (2007/08 Assignment) Consider the following code fragment that implements a software solution to the mutual exclusion
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: problem for two threads. Argue for its correctness or show a case in which it fails. int favoredThread = 1; bool t1WantsToEnter = false; bool t2WantsToEnter = false; T1 T2 while (!done) { while (!done) { //enterMutualExclusion //enterMutualExclusion t1WantsToEnter = true; t2WantsToEnter = true; while (favoredThread != 1) { while (favoredThread != 2) { while (t2WantsToEnter); while (t1WantsToEnter); favoredThread = 1; favoredThread = 2; } } //inside critical section //inside critical section //exitMutualExclusion //exitMutualExclusion t1WantsToEnter = false; t2WantsToEnter = false; //outside critical section //outside critical section } }...
View Full Document

This note was uploaded on 12/01/2010 for the course CS 2342 taught by Professor Dr during the Spring '10 term at HKU.

Ask a homework question - tutors are online