心得分享

Card image cap

王同學 報告/作業 分享經驗 os 作業 16/03

os 作業 16/03
名稱 os 作業 16/03

Homework Chapter 6-1
03/15/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

1. Mutual Exclusion. If a process is executing in its critical section, then no other processes can be executing in the same critical sections.
2. Progress. If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then it have to choose a process to enter the C.S in a limit time.
3. Bounded Waiting. A bound must exist a time for the waiting process to notice that how long it will take to be allowed to enter the C.S.

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?

Since the turn decides if the process have the authorization to get in the C.S.The eventual value of turn will be the critical fact for 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?
When read is in busy waiting, it will perform write, when write is in the busy waiting, the read can run , it can prevent each other from using the resource at the same 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.

readers uses mutex to control the reader to get in or not , and also depending the value of mutex, it can decide if the other readers can read the data , but the writer simply uses wrt to control weather it can get in or not, the reason of that is due to the fact that there are way too much reader that wants to get in, so the system have to control the amount of access with reader so that the writer can get in , the reader can be controlled by mutex ,and the writer can be signaled simply by wrt with get in or not , it is much more simpler that it doesn’t need to be controlled by the mutex.
(2) why the readers also work on the “wrt” semaphore which is used by the writers.

When readers done its reading it will signal wrt to let writer start its operation.
wait(mutex);
readcount++;
if (readcount == 1)
wait(wrt);
signal(mutex);

reading is performed

wait(mutex);
readcount--;
if (readcount == 0)
signal(wrt);
signal(mutex):
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.

更新日期:2016/3/23 下午 03:49:18