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 15:00
I'm taking a class on how to make a movie, and it offers some apps that would be in the process. the thing is, i don't have any of those ha. if you have any tips on some apps i could use, that would be awesome. i don't have an iphone, so don't suggest any apps like imovie. i know that this is a weird question, but it would be super for me. : )
Answers: 2
question
Computers and Technology, 22.06.2019 17:40
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i.e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
question
Computers and Technology, 23.06.2019 10:00
Now, open this passage to read about fafsa requirements. describe the information you will need to provide in order to complete a fafsa. list at least three of the required documents you must include.
Answers: 3
question
Computers and Technology, 23.06.2019 12:30
How is the brightness of oled of the diaplay is controled
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
question
Mathematics, 25.11.2021 08:20
question
Mathematics, 25.11.2021 08:20
question
Computers and Technology, 25.11.2021 08:20
question
Mathematics, 25.11.2021 08:20
Questions on the website: 13722360