2016/05/22 2016/3/15 os作業 | |
---|---|
名稱 | 3/15 os作業 |
描述 | os |
日期 | 2016/05/22 |
課程名稱 | os |
指導教師 | 劉艾華 |
Homework Chapter 6-1
03/15/2016
1. Consider the three conditions for a solution of critical section problem to be a correct solution: Mutual Exclusion, Progress and Bounded Waiting. Please explain
Ans:
1)Mutual Exclusion : If process P1 is executing in its critical section then no other process can be executing in their critical sections.
2)Bounded waiting : A Bounding must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.
3)Progress: If no process id executing in its critical section and there exist some processes that wish to enter their critical section , then the selection of the processes that will enter the critical section next cannot be postponed indefinitely.
2. While Peterson’s solution is correct, please discuss the situation where P1 and P2 are entering the Critical Section at about the same time. How to decide which process can enter its Critical Section?
Ans:
If both processes try to enter at the same time , turn is set to both I and j at roughly the same time. Only one of these assignments lasts; the other will occur, but will be overwritten immediately. The eventually value of turn decides which of the two processes is allowed to enter its critical section first.
3. Please specify under what kind of situation where busy waiting can be considered advantageous?
Ans:
Busy waiting waste CPU cycles that some other process might be able to use productively. This type of semaphore is also called a spinlock. Spinlock are useful in multiprocessor systems. The advantage of a spinlock is that no context switch is required when a process must wait on a lock (context switch may take considerable time). Spinlock are useful when locks are expected to be held for short times.
4. Consider the reader program of the reader-writer problem below. Please explain
(1) why the readers need to use the semaphore “mutex” but the writers don’t.
(2) why the readers also work on the “wrt” semaphore which is used by the writers.
wait(mutex);
readcount++;
if (readcount == 1)
wait(wrt);
signal(mutex);
…
reading is performed
…
wait(mutex);
readcount--;
if (readcount == 0)
signal(wrt);
signal(mutex):
1): No reader will be kept waiting unless a writer has already obtained permission to use the shared database.
2):Once a writer is ready, that writer performs its write as soon as possible. If a writer is waiting to access the object, no new readers may start reading.
更新日期:2016/5/22 下午 03:39:36