Docsity

9 Solved Questions on Virtual Memory Process - Exam 1 | COMP 310, Exams of Operating Systems

Toggle sidebar
bg1
COMP 310, Operating Systems, Fall, 2004 Exam 1 November 3, 2004
This exam is closed book, closed notes. Please write all your answers and show
all your work in the blue book provided.
1. (5 points)
When a process context switch occurs, one of the things the OS must do is to
load in the new process’s address space. Describe what this means. Does this
happen with a thread context switch? Why or why not?
Loading in a new address space means directing the OS to refer to a new set of
pages in physical memory that are mapped to the new process’s virtual memory
space. This involves flushing the TLB and switching the page table the OS uses.
This does not happen on a thread context switch because threads share their
parent process’s address space.
2. (5 points)
What are the advantages of a shortest remaining job first (SRJF) scheduling
algorithm? What are the disadvantages? What is the primary difficulty in
implementing such an algorithm? How can SRJF be approximated by operating
systems?
Advantage: Smallest average wait time.
Disadvantage: Can lead to starvation of long jobs.
Difficulty: Hard to predict how long a job will run.
Solution: Base estimate of a job’s running time on that job’s past performance.
(Note: Estimating the job’s running time by looking at it’s resources or counting
the lines of code were not correct answers. You cannot know how long a job
will loop or if it will even use it’s resources. For those of you who have taken
Theory of Computation, this is equivelent to the Halting Problem, which is not
computable.)
3. (5 points)
The following is an implementation of Wait for a condition variable. Clearly
describe what could go wrong if interrupts are not disabled and there is no other
form of synchronization imposed. Note: I am looking for a problem that causes
a thread to get lost forever. Assume that threads may only appear once on the
ready queue (that is, if something tries to add a thread to the ready queue,
nothing happens if that thread is already on the ready queue).
void
Condition::Wait( Lock *l )
{
ASSERT( conditionLock -> isHeldByCurrentThread() );
1
pf3
pf4

Partial preview of the text

Download 9 Solved Questions on Virtual Memory Process - Exam 1 | COMP 310 and more Exams Operating Systems in PDF only on Docsity!

COMP 310, Operating Systems, Fall, 2004 Exam 1 November 3, 2004 This exam is closed book, closed notes. Please write all your answers and show all your work in the blue book provided.

  1. (5 points) When a process context switch occurs, one of the things the OS must do is to load in the new process’s address space. Describe what this means. Does this happen with a thread context switch? Why or why not? Loading in a new address space means directing the OS to refer to a new set of pages in physical memory that are mapped to the new process’s virtual memory space. This involves flushing the TLB and switching the page table the OS uses. This does not happen on a thread context switch because threads share their parent process’s address space.
  2. (5 points) What are the advantages of a shortest remaining job first (SRJF) scheduling algorithm? What are the disadvantages? What is the primary difficulty in implementing such an algorithm? How can SRJF be approximated by operating systems? Advantage: Smallest average wait time. Disadvantage: Can lead to starvation of long jobs. Difficulty: Hard to predict how long a job will run. Solution: Base estimate of a job’s running time on that job’s past performance. (Note: Estimating the job’s running time by looking at it’s resources or counting the lines of code were not correct answers. You cannot know how long a job will loop or if it will even use it’s resources. For those of you who have taken Theory of Computation, this is equivelent to the Halting Problem, which is not computable.)
  3. (5 points) The following is an implementation of Wait for a condition variable. Clearly describe what could go wrong if interrupts are not disabled and there is no other form of synchronization imposed. Note: I am looking for a problem that causes a thread to get lost forever. Assume that threads may only appear once on the ready queue (that is, if something tries to add a thread to the ready queue, nothing happens if that thread is already on the ready queue).

void Condition::Wait( Lock *l ) { ASSERT( conditionLock -> isHeldByCurrentThread() );

queue->Append((void*)currentThread); conditionLock->Release(); currentThread->Sleep(); conditionLock->Acquire(); }

The problem occurs when the thread (call it T1) is interrupted AFTER is releases the condition lock but BEFORE it goes to sleep. In this case, another thread may come along and signal the CV, thus taking T1 off the conditionLock queue and putting it on the ready queue. However, it is still on the ready queue (that’s where it went when it got interrupted), so nothing will happen. When T1 runs again it will immediately go to sleep, but now it is no longer on the CV queue, nor is it on the ready queue, thus it is lost forever. This is the only way I can see that the thread will get lost forever.

  1. (10 points) Illustrate how a semaphore can be used to implement a lock. You should write the methods Acquire and Release. You do not need to support error checking.

Semaphore *s = new Semaphore( 1 );

Lock::Acquire() { s->P(); }

Lock::Release() { s->V(); }

  1. (10 points) Consider the following code to synchronize two threads running the “go” func- tion. Thread 1 will call go(0) and thread 2 will call go(1) possibly, but not necessarily, inside a loop. Discuss whether this solution guarantees each of mu- tual exclusion and progress. You do not need a formal proof, but your argument should be convincing.

// Global variables Lock* mutex = new Lock(); Condition* hold = new Condition(); int turn = 0;

  1. (5 points) Describe the difference between deadlock prevention and avoidance. Be sure to clearly describe what each one is. Deadlock prevention is when the system implements policies that make it im- possible for at least one of the 4 deadlock conditions to occur (mutual exclusion, hold and wait, circular wait, and no preemption). Deadlock aviodance means that the four conditions can occur, but the system allocates resources such that the system remains in a safe state. That is, there will always be an ordering of processes such that each process could receive its remaining resources and run to completion.
  2. (5 points) Describe how your group solved the mating whales problem from Project 1. If there were any problems with your solution, what were they?
  3. (10 points total) a) (4 points) Suppose a machine uses paging with 512 byte pages, and has virtual addresses that are 16 bits. How many Virtual Pages are there in the virtual address space? 512 = 2^9 → 9 bits in offset 16 − 9 = 7 → 7 bits for VPN 27 = 128 Virtual Pages b) (6 points) Consider the portion of the page table given below. What is the Physical Address (in hex, please) for the virtual address 0x2A5? VPN PFN 1 6 2 7 3 2 4 0 ... ... 0x0CA