3/15 OS作業

名稱
3/15 OS作業
日期
3/23
課程名稱
作業系統
指導教師
劉艾華
心得
1.Mutual exclusion > If one process is executing their critical section, the second process which wish to do so will become blocked by the flag of the first process. If both processes attempt to enter at the same time, the last process to execute "turn = j" will be blocked.
Progress > Each process can only be blocked at the while if the other process wants to use the critical section. If both of flag[j] and turn==j conditions are true, the other will be allowed to enter the critical section. Upon exiting the critical section, will set flag[j] to false, releasing process i. The shared variable turn assures that only one process at a time can be blocked, and the flag variable allows one process to release the other when exiting their critical section.
Bounded Waiting > As each process enters their entry section, they set the turn variable to be the other processes turn. Since no process ever sets it back to their own turn, this ensures that each process will have to let the other process go first at most one time before it becomes their turn again.
2.The final value of turn will decide which process enters its critical section first.

3.Busy waiting wastes CPU cycles that some other process might be able to use productively. This type of semaphore is also called spinlock.

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

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