Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Operating Systems question The following program segment is used to manage a fin

ID: 3708965 • Letter: O

Question

Operating Systems question

The following program segment is used to manage a finite number of instances of a resource such as a commercial software license. When a user starts the application, the license count is decremented. When it is terminated, the count is incremented. If all licenses are in use, requests to start the application are denied. There is no queuing of requests. Using a general solution, the maximum and available number of licenses is defined as follows:

#define MAX_RESOURCES 5

int available_resources = MAX_RESOURCES;

The preceding code produces a race condition. Do the following: (a) Identify the location (or locations) in the code where the race condition occurs. (10 pts) (b) Identify the data involved in the race condition. (5 pts) (c) Using a semaphore, fix the race condition. It is OK to modify decrease_count so that the calling process is blocked until sufficient resources are available. (20 pts)

When a process wishes to obtain a license, it invokes the decrease count) function passing in 1: // Decrease available resources by count resources // return O if no resources are available, I if successful int decrease_count(int count) if (available resources>count) available_resources --count; return return 0; When a process wants to return a number of resources, it calls increase_count0 with the count // Increases available_resources by count void increase_countint count) available resources +-count;

Explanation / Answer

Solution:

1)

The race conditions occur in the methods named as decrease_count and increase_count.

2)

The data involved are:

available_resources -= count;

available_resources += count;

3)

Semaphore will be for fixing the race condition:

wait(mutex)

{

while mutex<= 0

}

signal(mutex)

{

mutex= mutex + count;

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)