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 program segment is used to manage a finite number of instances of an available resource. the maximum number of resources and the number of available resources are declared as follows:

#define max resources 5
int available resources = max resources;

when a process wishes to obtain a number of resources, it invokes the decrease_count() function:

/* decrease available resources by count resources */
/* return 0 if sufficient resources available, */
/* otherwise return -1 */
int decrease_count(int count) {
if (available resources < count)
return -1;
else {
available resources -= count;
return 0;
}
}
when a process wants to return a number of resources, it calls the increase_count() function:

/* increase available resources by count */
int increase_count(int count) {
available resources += count;
return 0;
}
the preceding program segment produces a race condition. do the following:
1. identify the location and variables involved in the race condition.

2. using a pthread_mutex_lock, fix the race condition.

3. the decreasecount() function currently returns 0 if sufficient resources are available and −1 otherwise. rewrite the two functions using a pthread mutex and a pthread condition so that the decreasecount() function suspends the process until sufficient resources are available. this will allow a process to invoke decreasecount() by simply calling decreasecount(count). the process will return from this function call only when sufficient resources are available.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 00:00
11. is the ability to understand how another person is feeling. a. authority b. sympathy c. empathy d. taking a stand
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
question
Computers and Technology, 22.06.2019 22:00
Consider the following declarations (1, 2, 3, 5, 7)class bagtype{public: void set(string, double, double, double, double); void print() const; string getstyle() const; double getprice() const; void get(double, double, double, double); bagtype(); bagtype(string, double, double, double, double); private: string style: double l; double w; double h; double price; }; a.) write the definition of the number function set so that private members are set according to the parametersb.) write the definition of the member function print that prints the values of the data membersc.) write the definition of the default constructor of the class bagtype so that the private member variables are initialized to "", 0.0, 0.0, 0.0, 0.0, respectively d.) write a c++ statement that prints the value of the object newbag.e.) write a c++ statement that declares the object tempbag of type bagtype, and initialize the member variables of tempbag to "backpack", 15, 8, 20 and 49.99, respectively
Answers: 3
question
Computers and Technology, 23.06.2019 09:10
Effective character encoding requires standardized code. compatible browsers. common languages. identical operating systems.
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
Chemistry, 28.12.2020 23:00
question
Mathematics, 28.12.2020 23:00
question
Mathematics, 28.12.2020 23:00
question
Mathematics, 28.12.2020 23:00
question
Mathematics, 28.12.2020 23:00
question
English, 28.12.2020 23:00
question
English, 28.12.2020 23:00
Questions on the website: 13722362