Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 01:00, lusciousl
Petrică, tânăr licean în clasa a ix-a, a primit în dar de la părinţii săi un cont bancar pentru micile sale cheltuieli curente. el este pasionat de internet banking şi îşi verifică cu grijă toate tranzacţiile efectuate. pentru creşterea securităţii tranzacţiilor online, banca îi furnizează lui petrică un număr pe care el va trebui să îl modifice, obţinând un număr tan – număr de autentificare a tranzacţiei (transaction authentication number). regula de obţinere a numărului tan este următoarea: se formează cel mai mic număr par din toate cifrele numărului furnizat de bancă. cerinţă cunoscând numărul n furnizat de bancă, să se determine numărul tan obţinut de petrică. date de intrare fişierul tan. in conţine pe prima linie numărul natural n cu semnificaţia din enunţ. date de ieşire fişierul de ieşire tan. out va conţine o singură linie pe care va fi scris numărul tan cerut. restricţii • 0 < n < 18*1018 • n are cel puţin o cifră pară • numărul tan obţinut nu poate conţine zerouri nesemnificative
Answers: 2
image
Computers and Technology, 23.06.2019 11:00, la200564
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
image
Computers and Technology, 23.06.2019 23:40, lexiecooley
4. what is the reason for including the following code snippet in the header file animal. h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
image
Computers and Technology, 24.06.2019 02:30, journeyhile5
How to apply the fly in effect to objects on a slide
Answers: 1
Do you know the correct answer?
Assume that a finite number of resources of a single resource type must be managed. processes may as...

Questions in other subjects: