(Chapter 6 problem 4 of Modern Operating System, 4th Edition) In Fig. 6-1 the re
ID: 3714114 • Letter: #
Question
(Chapter 6 problem 4 of Modern Operating System, 4th Edition) In Fig. 6-1 the resources are returned in the reverse order of their acquisition. Would giving them back in the other order be just as good?
typedef int semaphore; semaphore resource1 typedef int semaphore; semaphore resource 1; semaphore resource_2; void process_A(void) ( void process_A(void) ( down(&resource-1;) use resource-1); up/&resource-1;) down(&resource; 1); down(&resource-2;) use_both resources); up(&resource2;); up(&resource-1;): Figure 6-1. Using a semaphore to protect resources. (a) One resource. (b) Two resources.Explanation / Answer
In the above process let P1 acquire resource 1 first and then acquires resource 2, now by the time resource 2 is being acquired no other process can call for resource 1 as it is already acquired.
After acquiring both resource 1 and 2 the current process P1 enters the critical section (section where process uses the resources to perform corresponding actions).In between no processes can call for resource 1 or resource 2 as they are being used by process P1.
Now if resource 1 is released first by P1, then any other process can access the resource 1 and alter its value and resource 2 might have been using value of resource 2 and so the result for process P1 becomes inconsistent.
Even if resource 1 is released by any process it has to wait for resource 2 to be released by current process P1.Thus consumes CPU time.
While in the given case, where resource 2 is released before resource 1 no process can enter as every process must acquire resource 1 first to acquire resource 2.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.