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 18:30
Which of these options are the correct sequence of actions for content to be copied and pasted? select content, click the copy button, click the paste button, and move the insertion point to where the content needs to be inserted. click the copy button, select the content, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, click the copy button, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, move the insertion point to where the content needs to be inserted, click the copy button, and click the paste button.
Answers: 3
question
Computers and Technology, 22.06.2019 19:30
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 3
question
Computers and Technology, 24.06.2019 07:30
Jason is working on a microsoft excel worksheet and he wants to create a print preview shortcut. his teacher asks him to access the customization option to create the new shortcut. which two tabs should jason select to place the print preview shortcut on the worksheet toolbar? a. new tab (custom) and new group (custom) b. new file tab (custom) and new tab (custom) c. new custom group and new command d. new custom tab and new command
Answers: 2
question
Computers and Technology, 24.06.2019 23:00
Systolic pressure is a measure of blood pressure when the ventricles relax and fil with blood ture or false
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
Questions on the website: 13722362