心得分享

Card image cap

陳同學 報告/作業 分享經驗 0323 0315 OS作業

0323 0315 OS作業
名稱 0315 OS作業
日期 0323
課程名稱 作業系統
指導教師 劉艾華

105.03.15
I. Consider the three conditions for a solution of critical section problem to be a correct solution: Mutual Exclusion, Progress and Bounded Waiting. Please explain
1. Mutual Exclusion:If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.
2. Progress:If no process is execution in its critical section and there exist some processes that wish to enter their critical section, then the selection of the process that will enter the critical section next cannot be postponed indefinitely.
3. 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.
II. 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?
If both processes try to enter at the same time, turn is set to both i and j at the same time. Only one of these assignments lasts; the other will occur, but will be overwritten immediately. The eventual value of turn decides which of the two processes is allowed to enter its critical section first.
III. Please specify under what kind of situation where busy waiting can be considered advantageous?
When reader is in busy waiting and writer is using the resource and when writer is in busy waiting, reader is using the resource. It’s less likely to happen the clash of using resource between read and write to use CPU.
IV. 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. When there’s no data in the buffer, readers need to wait. While the capacity is not limited so writers can keep producing.
2. Because the shared database can only for one writer using or for one or more reader using. When the shared database is used, wrt will become 0 while the executing is finished, wrt will become 1.

更新日期:2016/3/23 下午 11:22:34