03/23/2016 03/15 OS 作業

名稱
03/15 OS 作業
日期
03/23/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
Answer: 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 some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in deciding which will enter its critical section next and this selection cannot be postponed indefinitely
Bounded waiting. There exists a bound, or limit, 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?
Answer: We should first determine which process has equals to 1. If the process has equals to 1 then it can ready to enter the critical solution first.
3. Please specify under what kind of situation where busy waiting can be considered advantageous?
Answer: Busy waiting means that a process is waiting for a condition to be satisfied in a tight loop without relinquishing the processor. Alternatively, a process could wait by relinquishing the processor, and block on a condition and wait to be awakened at some appropriate time in the future. Busy waiting can be avoided but incurs the overhead associated with putting a process to sleep and having to wake it up when the appropriate program state is reached.
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. if a writer and reader access the database simultaneously, chaos may ensue. That’s why only readers need mutex.
2. The mutex semaphore is used to ensure mutual exclusion when the variable read_count is updated. The read_count variable keeps track of how many processes are currently reading the object. The semaphore functions as a mutual exclusion semaphore for the writers. It is also used by the first or last reader that enters or exits the critical section.