心得分享

Card image cap

許同學 報告/作業 分享經驗 3/15 OS作業

3/15 OS作業
名稱 3/15 OS作業
日期 3/23
課程名稱 OS
指導教師 劉艾華

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: Mutual Exclusion: If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.
Progress: If no process is 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.
Bounded Waiting: A bound 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

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: To enter the critical section, process Pi first sets flag[ i ] to be true and then sets turn to the value j, thereby asserting that if the other process wishes to time ,turn will be set to both i and j at roughly the same time.

3. Please specify under what kind of situation where busy waiting can be considered advantageous?

While a process is in its critical section ,any other process that tries to enter its critical section must loop continuously in the call to acquire(). In fact, this type of mutex lock is also called a spinlock because available. This continual looping is clearly a problem in a real multiprogramming system, where a single CPU cycles that some other process might be able to use productively.

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):
Ans:
(1) The mutex semaphore is used toensure mutual exclusion when the variable read_count is updated. The read_count variable keeps track of how many processes are currently reading the object.
(2) If a writer is in the critical section and n readers are waiting, then one reader is queued on rw_mutex, and n-1 readers are queued on mutex. Also observe that, when a writer executes signal ,we may resume the execution of either the waiting readers or a single waiting writer.

更新日期:2016/3/24 上午 12:46:08