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 02:30
Write a program that takes in 3 inputs [players (int type), expected game time (double type), team (char type)] and calculates actual game time (double) based on the following conditions: if the number of players or the expected game time is less than or equal to zero, it should output wrong input if the number of players is greater than 0 and less than or equal to 6 and if they are on the â€r’ or â€r’ team, their game time will be 10% faster. and if they are on the â€b’ or â€b’ team, their game time will be 15% faster. and if they are on the â€y’ or â€y’ team, their game time will be 20% faster. and if they are on any other team, they will play 0% faster. if the number of players is greater than 6 but less than or equal to 12 and if they are on the â€r’ or â€r’ team, their game time will be 20% faster. and if they are on the â€b’ or â€b’ team, their game time will be 25% faster. and if they are on the â€y’ or â€y’ team their game time will be 30% faster. and if they are on any other team, they will play 0% faster. if the number of players is greater than 12 but less than or equal to 18 and if they are on the â€r’ or â€r’ team, their game time will be 30% faster. and if they are on the â€b’ or â€b’ team, their game time will be 35% faster. and if they are on the â€y’ or â€y’ team, their game time will
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
What are loans to a company or government for a set amount of time
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
Column a of irma’s spreadsheet contains titles for each row, but her document is too big and will be printed three pages across. she wants to be sure that every page will be understood. what can irma do to with this problem?
Answers: 3
question
Computers and Technology, 24.06.2019 10:30
This device directs network traffic. bridge hub nic repeater router switch
Answers: 3
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, 22.06.2019 11:00
Questions on the website: 13722361