20160324 20160324 OS作業

名稱
20160324 OS作業
日期
20160324
課程名稱
OS
指導教師
劉艾華
心得
1-1 Mutual Exclusion:
When a thread tries to acquire a mutex, it gains the mutex if it is available, otherwise the thread is set to sleep condition. Mutual exclusion reduces latency and busy-waits using queuing and context switches.

1-2 Progress:
Progress means that the process will eventually do some work - an example of where this may not be the case is when a low-priority thread might be pre-empted and rolled back by high-priority threads. Once your processes reach their critical section they won't be pre-empted, so they'll make progress.

1-3 Bounded waiting
Bounded waiting means that the process will eventually gain control of the processor - an example of where this may not be the case is when another process has a non-terminating loop in a critical section with no possibility of the thread being interrupted. Your code has bounded waiting IF the critical sections terminate AND the remainder section will not re-invoke the process's critical section

2 Peterson's Solution
If we ever arrive at the situation where both processes call enter region at the same time, one of the processes will set the turn variable, but it will be immediately overwritten.
Assume that process 1 sets turn to zero and then process 2 immediately sets it to 1. Under these conditions process 1 will be allowed to enter its critical region and process 2 will be forced to wait.

3 When two or more processes want to enter the same critical section, something has to be done to prevent more than one process from entering it. An example would be the famous printing problem (two processes want to print at the same time) or two processes have shared memory.

4-1
Because there are way too more readers so it has to use mutex to control it.

4-2
Because only when writer is ready the reader can get in.