心得分享

Card image cap

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

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

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.
(1). 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?

(1). First sets flag[i] to be true and then sets turn to the value j, thereby asserting that if the other process wishes to enter the critical section, it can do so. If both processes try to enter at the same time, turn will be set to both I and j at roughly the same time. Only one of these assignments will last; the other will occur but will be overwritten immediately.

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

(1). Spinlock is a kind of situation, its advantage is in that no context switch is required when a process must wait on a lock, and a context switch may take considerable time. Thus, when locks are expected to be held for short times, spinlocks are useful.

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). In applications that have more readers than writers. This is because reader-writer locks generally require more overhead to establish than semaphores or mutual-exclusion locks. The increased concurrency of allowing multiple readers compensates for the overhead involved in setting up the reader-writer lock.

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

5. Review the construct of Monitor and understand why the Dinning Philosopher problem can be solved by a Monitor with Pickup and Putdown function. Will give a test for this question next class.

(1). Philosopher i must invoke the operations pickup and putdown in the following sequence:
dp.pickUp(i);
...
eat
...
dp.putDown(i);
This solution ensures that no two neighbors are eating simultaneously, and no deadlocks will occur. However, it is possible for a philosopher to starve to death.

更新日期:2016/3/23 下午 09:48:10