subject

Assume that a finite number of resources of a single resource type must be managed. processes may ask for a number of these resources and -once finished-- will return them. as an example, many commercial software packages provide a given number of licenses, indicating the number of applications that may run concurrently. when the application is started, the license count is decremented. when the application is terminated, the license count is incremented. if all licenses are in use, requests to start the application are denied. such requests will only be granted when an existing license holder terminates the application and a license is returned. the following java class is used to manage a finite number of instances of an available resource. note that when a process wishes to obtain a number of resources, it invokes the decreasecount() method. similary, when a process wants to return a number of resources, it calls class manager{public static final int max_resources = 5; private int availableresources = max_resources; /***decrease availableresources by cuont resources.*return 0 if sufficent resources available,*otherwise return -1*/public in decreasecount(int count) {if (availableresources < count)return -1; else {availableresources -= count; return 0; }/* increase availableresources by count resources. */public void increasecount(int count) {availableresources += count; }}however, the preceding program segment produces a race condition. do the following: a.) identify the data involved in the race condition. (do not answer)b.) identify the location (or locations) in the code where the race condition occurs.(do not answer)c.) using java synchronization, fix the race condition. also modify decreasecount() so that a thread blocks if there aren't sufficent resources available and demonstrate that your soulution works. (answer and show that the program runs without the race condition) if you can get it to work with the code i provided below do the following up above. package thread; public class thread { public static final int max_resources = 5; private int availableresources = max_resources; public int decreasecount(int count){ synchronized(this) { if (availableresources < count) return -1; else { availableresources -= count; } return 0; // resource available // end of else }} // end function decreasecountpublic void increasecount(int count) { synchronized(this) { availableresources += count; }} // end function increase countpublic void main(string[] args){ int retval; system. out. println("thread (multi thread) demonstration to nullify race condition"); for (int i=1; i< =10; i++) { increasecount(2); retval = decreasecount(1); retval = decreasecount(1); }}} // end of class thread formerly called as manager class

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 00:10
How does access indicates that a filter has been applied to a specific column
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
In the context of an internet connection, llc stands for leased line connection liability limited company local loop complex local loop carrier
Answers: 1
question
Computers and Technology, 23.06.2019 06:20
Which text function capitalizes the first letter in a string of text? question 10 options: upper capital first proper
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks are greater than rewards. ( need )
Answers: 1
You know the right answer?
Assume that a finite number of resources of a single resource type must be managed. processes may as...
Questions