hw3 PDF
hw3 PDF
hw3 PDF
Homework Assignment 3
Due: Wednesday, 10 March 2004, 4:30PM , HW box, EUII
Do true ->
V(car-avail)
P(car-taken)
V(car-filled)
Part a: Assume there is only one process (in addition to the hardware),
and delay has a single argument:
delay(integer n). Write the code for the process (yes, this
is intended to be simple)
and for the monitor (the major effort will be in writing the code
for the procedures
delay and tick after you
declare the globals and conditions).
This question concerns the Buddy System, an approach to partition main memory for the purpose of
allocating contiguous areas of main memory to processes. In a buddy system, memory blocks are available
K
of size 2 , L <= K <= U, where
U
• 2 = smallest block that is allocated
U U
• 2 = largest block that is allocated; generally, 2 is the size of the entire memory available for
allocation.
U
To begin, the entire space available for allocation is treated as a single block of size 2 . If a request of size
U −1 U
s such that 2 < s ≤ 2 is made, then the entire block is allocated. Otherwise, the block is split into two
U −1 U −2 U −1
equal buddies of size 2 . If 2 <s≤2 , then the request is allocated to one of the two
buddies. Otherwise, one of the buddies is split in half again. This process continues until the smallest block
greater than or equal to s is generated and allocated to the request. At any time, the buddy system maintains
i
a list of holes (unallocated blocks) of each size 2 . A hole may be removed from the (i+1) list by splitting it
in half to create two buddies of size in the I list. Whenever a pair of buddies on the I list both become
unallocated, they are removed from the list and coalesced into a single block on the (i+1) list. Here is a
question:
A megabyte block of memory is allocated using the buddy system. Show the results of the following
sequence in a figure that shows the block of memory allocated at each step, the unallocated blocks, and the
buddies:
A: request 70k
B: request 35k
C: request 80k
release A
D: request 60k
Release B
Release D
Release C
#process i
while TestAndInc (L) > 0
do null;
critical section for process i
L:= 0;
#remainder of processes
Coend
a) Does this solution provide mutual exclusion? Explain.
b) Is it possible for L to overflow: Explain. How might this impact
your answer to a), depending on your assumptions on the effect of
overflow?
od