3/15 3/15os

名稱
3/15os
描述
3/15os
日期
3/15
課程名稱
作業系統
指導教師
劉艾華
心得
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.
A:

Mutual Exclusion:
If there is one process executing in critical section, then no other processes can be executing in that 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 the critical sections after a process has made a request to enter its critical section

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?

A:

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.

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

Busy-waiting itself can be made much less wasteful by using a delay function found in most operating systems. This puts a thread for a specified time, during which the thread will waste no CPU time. If the loop is checking something simple then it will spend most of its time and will waste very little CPU time.

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)

A:
(1)No reader will be kept waiting unless a writer has already obtained permission to use the shared database.

(2)if a writer is ready, that writer performs its write as fast as possible. If a writer is waiting to access the object, no new readers could start reading.