Final Exam Part 1 Flashcards
True/False: Only one thread can be in monitor at a time
True
Difference between p() and wait()?
P only blocks if c < 0, wait() ALWAYS blocks
Difference between v() and signal()?
The v() signal is NEVER lost, where signal() may be lost if the queue is empty.
What is the output of the following code if T1 goes first? if T2 goes first?
procudere procA{
b.signal
a.wait
}
procedure procB{
b.wait
a.signal
}
T1 while(1){ AB.procA print(a) }
T2
while(1){
AB.procB
print(b)
T1 first: deadlock
T2 first: [ab]*
A file is to be shared among different processes, each of which has a unique number. The file can be accessed simultaneously by several processes, subject to the following constraint: The sum of all unique numbers associated with all the processes currently accessing the file must be less than n. Write a monitor to coordinate access to the file.
Monitor resourceAllocate
{
int sum;
condition c;
void AccessFile(int num) { while(sum+num>=n) { c.wait(); } sum+=num; }
void FinishAccessing(int num) { sum= sum-n; c.signal(); }
void init() { sum=0; } }
Define paging
A technique to implement virtual memory
The key issue in virtual memory is WHEN to bind variables to a location. What are three different ways of doing this? Which one is used today?
- At compile time. Compiler determines where to place program in MM.
Disadvantages: program has to be recompiled every time it is run. - At load time.
Disadvantage: Program has to remain in the same location, and the entirety of the program needs to be loaded in MM. - At runtime. This one is used regularly.
What are the four different memory management techniques?
- Contiguous
- Paging
- Segmentation
- Segmentation + Paging
Address binding is done by the _____.
MMU (Memory management unit)
How is a virtual address converted to a physical address in the contiguous memory management scheme?
- CPU generates virtual address.
- There is a MBR and an MLR in the MMU. The physical address created is the virtual address + MBR so long as it is <= the MLR.
What would the physical address be if a CPU generated a virtual address of 5, and the MBR and MLR had values of 270 and 595 respectively?
275
Consider MM with holes as shown below:
Hole 1- 68K Hole 2- 96K Hole 3- 78K Hole 4- 25K Hole 5- 80K
If two processes wanted to get into main memory with sizes of 75K and 25K respectively, which hole would each process go into? Answer the question with all four contiguous memory policies.
First Fit: Hole 2, Hole 1
Next Fit: Hole 2, Hole 3
Best Fit: Hole 3, Hole 4
Worst Fit: Hole 2, Hole 5
What are the two major disadvantages of the contiguous memory management scheme?
- Complete program must be loaded into MM.
2. Memory fragmentation.
Define the two different types of fragmentation.
Internal: Hole within program
External Fragmentation: Holes between programs
Out of the four contiguous memory policies, which leads to the most fragmentation? Which type of fragmentation is it? Why?
Best fit. Consider the following scenario:
Hole: 25K
Process 23K
Process will give entire 25K to process since the 2K will not be of any use elsewhere. This means that internal fragmentation is occurring because the process has 2K worth of space it isn’t using.