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, 21.06.2019 16:50
3.2.5 suppose that we have an estimate ahead of time of how often search keys are to be accessed in a bst, and the freedom to insert items in any order that we desire. should the keys be inserted into the tree in increasing order, decreasing order of likely frequency of access, or some other order? explain your answer.
Answers: 1
question
Computers and Technology, 21.06.2019 22:00
3. (6 pts) internally in the computer, with few exceptions, all numerical computation is done using binary numbers. output, however, often uses ascii, which is formed by appending 011 to the left of a bcd code. thus, an algorithm that directly converts a binary integer to a bcd integer is very useful. here is one such algorithm 1) draw lines to the left of the binary number to bound the expected bcd decades. (each decade is a group of 4 bits.) move the binary number one bit to the left. add 0011 to each bcd decade containing a binary value> 0100 repeat steps 2-3 until the last bit in the binary number has been moved into the least significant decade position. (note that when the last bit has been shifted into bcd decade, step 3 is not repeated.) read the bcd result. 2) 3) 4) 5) a) execute the algorithm for the binary number 1101101 b) execute the algorithm for the binary number 01110101110 4. (4 pts) represent the decimal number 3568 in bcd; excess-3 code; ascil; and hex.
Answers: 1
question
Computers and Technology, 23.06.2019 15:10
What role did women fill during world war ii?
Answers: 1
question
Computers and Technology, 23.06.2019 22:40
22. sata3 allows for data transfer rates of 600 mb/s. explain why you would likely not be able to copy data from one hard drive to another at anywhere close to this speed. also, what could be upgraded on the computer to achieve transfer speeds closer to 600 mb/s
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, 16.10.2021 05:10
question
Mathematics, 16.10.2021 05:10
question
Social Studies, 16.10.2021 05:10
question
Chemistry, 16.10.2021 05:10
question
Mathematics, 16.10.2021 05:10
question
Biology, 16.10.2021 05:20
Questions on the website: 13722360