5/22 OS作業 3/15

名稱
OS作業 3/15
日期
5/22
課程名稱
作業系統
指導教師
劉艾華
心得
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:

a. Mutual Exclusion: If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.

b. 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.

c. 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:
If both processes try to enter at the same time, turn is set to both processes at roughly the same time, but the eventual value of turn will decides which of the two processes is allowed to enter its critical section.




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

Answer:

While read is busy waiting, write is using CPU. While write is busy waiting, read is using CPU. Therefore, there is less chance to happen conflict between read and write to use CPU.




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:

Because reader has priority, no reader will be kept waiting unless a writers has already obtained permission to use the shared database. If readcount is 1,and the writer do not finish writing, reader will wait until waiting finish, but if readcount is 2, reader No.2 can come into WRT work with reader No.1 casue the starvation of writer.