Cover Page Page 1 of 13
SECTION A - Multiple Choice (20 marks - 1 mark per question)
In the following multiple choice questions, more than one choice may be correct. Circle all correct answers. Full marks will be given where all correct answers are circled. Marks will be deducted within each question for incorrect answers.
SECTION B - Answer all questions
To allow Santa to get some sleep, the elves can only wake him when three of them have problems. When three elves are having their problems solved, any other elves wishing to visit Santa must wait for those elves to return.
If Santa wakes up to find three elves waiting at his shop's door, and the last reindeer has returned from the tropics, Santa has decided that the elves must wait until after Christmas, because it is more important to get the sleigh ready. (It is assumed that the reindeer don't want to leave the tropics, and therefore they stay there until the last possible moment.)
The last reindeer to arrive must wake up Santa while the others wait in a warming hut before being harnessed to the sleigh.
Write a suite of synchronized processes that will solve this problem. You may use any programming language you prefer, including pseudo code, and you must show the design and development of your solution. Python solutions will attract a bonus mark. (20+ marks)
I solved this problem by writing a process skeleton for each active participant type, and then adding the synchronization and mutual exclusion semaphores. Finally the appropriate initializations were added.
Santa Outline: (one only instance) 5 total
while (TRUE) do
wait(WakeSanta) 1 for loop forever in each process; OR, identification of process set
if (reindeer at door) then 1 for test on why woken
1 for handling reindeer
check that reindeer has rousted other reindeer
ready sleigh
deliver toys
else 1 for handling elves
for (each elf) do 1 for remembering there's 3 of them
solve problem
send back to work
end for
end if
end while
Reindeer Outline: (one instance per reindeer, i.e., nine instances) 5 total
while (TRUE) do see Santa while(not Dec. 24 and not tired of South Pacific) do vacation in South Pacific end while 1 for non-synchronized stuff return to North Pole if last reindeer to return then 1 for last reindeer test for (each reindeer in warming hut) do signal(AllReindeerPresent) 1 for rousting other reindeer end do signal(WakeSanta) 1 for signalling wake up else # wait in warming hut wait(AllReindeerPresent) 1 for handling not last reindeer end if hook up to sleigh fly Santa around world return to South Pacific end while
Elf Outline: (one instance per elf; arbitrarily many) 8 total
while (TRUE) do see Santa while (no problem) do 1 for non--synchronized stuff build toy end while wait(mutex); problemElfCount++; signal(mutex) 1 for mutex if problemElfCount < 3 wait(NeedMoreElves) 1 for less than 3 need to wait else if problemElfCount >= 3 then # gather other 2 elves with problems signal(NeedMoreElves); signal(NeedMoreElves); 1 for gathering 3 elves wait(mutex); problemElfCount -= 3; signal(mutex) 1 for mutex end if # if a group of elves off to see Santa # have your group wait wait(ElvesGroupFinished) 1 for only 1 group at a time # this group OK to go signal(WakeSanta) 1 for signalling wake up see Santa # On returning, send another group of elves if there is one waiting signal(ElvesGroupFinished) 1 for releasing next group end while
Initialization 2 total
semaphore mutex = 1 1 for correct initializations; OR identification of event set semaphore WakeSanta = 0 semaphore AllReindeerPresent = 0 semaphore NeedMoreElves = 0 semaphore ElvesGroupFinished = 1 1 for correct semaphores; OR identification of variable set1 bonus mark if solution presented in Python. Either Exact syntax, or extensive class description (e.g., __init__ and/or run definitions, etc., required for this mark!
Be lenient in the interpretation of these statements. For example, if a student correctly identifies that each of the elves and reindeer processes has a "wakeup Santa" requirement, then award the mark for this, even if not correctly coded.
is required. 2 marks for correct (consistent)
diagram, 1 mark for control flow, 1 mark for parallel
execution of IO, 1 mark for concurrent (interleaved)
flow of process execution.
blocked = [false,false]
turn = 0
class P(Thread):
global blocked,turn
def __init__(self,id): self.id = id
while true:
# entry code
blocked[self.id] = true
while turn != self.id:
while blocked[1-self.id]:
turn = self.id
# end entry code
# critical section
# exit code
blocked[self.id] = false
# end exit code
p0 = P(0); p1 = P(1);
p0.start(); p1.start();
Explain why the algorithm fails. (5 marks)
Alternatively, just give 5 marks for a coherent explanation of all detail
Consider the following set of processes with the arrival for execution at the times indicated and the total required burst times listed.
| Process | Arrival Time (mS) | Burst Time (mS) |
|---|---|---|
| P1 | 0 | 7 |
| P2 | 2 | 10 |
| P3 | 8 | 5 |
| P4 | 13 | 3 |
| P5 | 18 | 6 |
Answer the following questions (using illustrations or tables as necessary) for the two CPU scheduling algorithms:
There is an ambiguity about whether arriving processes get priority over jobs already in the system, hence there are two valid solutions for the Round Robin, depending upon whether processes already in the system have priority (a), or arriving processes have priority (b).
Round Robin (a: resident processes have priority)
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| P1 | P1 | P1 | |||||||||||||||||||||||||||||
| P2 | P2 | P2 | P2 | P2 | P2 | ||||||||||||||||||||||||||
| P3 | P3 | P3 | P3 | ||||||||||||||||||||||||||||
| P4 | P4 | ||||||||||||||||||||||||||||||
| P5 | P5 | P5 | P5 | ||||||||||||||||||||||||||||
Round Robin (b: arriving processes have priority)
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| P1 | P1 | P1 | |||||||||||||||||||||||||||||
| P2 | P2 | P2 | P2 | P2 | P2 | ||||||||||||||||||||||||||
| P3 | P3 | P3 | P3 | ||||||||||||||||||||||||||||
| P4 | P4 | ||||||||||||||||||||||||||||||
| P5 | P5 | P5 | P5 | ||||||||||||||||||||||||||||
Non-preemptive Shortest Job First
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| P1 | |||||||||||||||||||||||||||||||
| P2 | P2 | ||||||||||||||||||||||||||||||
| P3 | P3 | ||||||||||||||||||||||||||||||
| P4 | P4 | ||||||||||||||||||||||||||||||
| P5 | P5 | ||||||||||||||||||||||||||||||
| Process | RR(a) | RR(b) | SJF |
|---|---|---|---|
| P1 | 11 | 11 | 7 |
| P2 | 22 | 27 | 15 |
| P3 | 21 | 15 | 17 |
| P4 | 9 | 9 | 7 |
| P5 | 13 | 13 | 13 |
| Process | RR(a) | RR(b) | SJF |
|---|---|---|---|
| P1 | 4 | 4 | 0 |
| P2 | 12 | 17 | 5 |
| P3 | 16 | 10 | 12 |
| P4 | 6 | 6 | 4 |
| P5 | 7 | 7 | 7 |
Consider an operating system MicroHard Doors 2001, which is using a basic paging system (without using demand paging) with a logical address space of 4,096Kbyte and page size of 128Kbyte. The hardware characteristics of the computer system are as follows:
Main memory size = 32 Mbyte (1M = 1024K, 1K = 1024 bytes)
Main memory access time = 75 nS
Smallest addressable unit = 4 bytes (i.e. 1 word)
It is worth noting that I (ajh) computed these values by hand. They are not onerous calculations. However, many students found them so:
| This page maintained by John Hurst. For further information please visit my ... | |||
|
This page was generated from an XML file, which was last modified at 20011111T152006+11 Maintainer use only; not generally accessible: File version CSSE Server | |||
|
|