Suppose there is a resource that can be used by upto 2 processes at a time. The
ID: 3780244 • Letter: S
Question
Suppose there is a resource that can be used by upto 2 processes at a time. The method AccessResource provides access to this resource. To ensure that only two processes can access resource at a time, the processes are not allowed to call AccessResource directly. Instead, they call the function RequestResource which in turn allows them to access the resource.
The outline of RequestResource is as follows
RequestResource
{
YOUR CODE
AccessResource();
YOUR CODE
}
Your task is to fill in the portion marked with `YOUR CODE' so that only two processes can access the resource at a time even though more than two can request it at a time. (Note that what goes inside AccessResource is irrelevant to your assignment. Your job is to make sure that at most two of them can access it at a time)
1. Solve this problem using testset instruction. This solution may use busy waiting and does not have to guarantee fairness.
2. Solve this problem using semaphores. This solution may not use busy waiting and has to guarantee fairness.
please use c++
Explanation / Answer
is to fill in the portion marked with `YOUR CODE' so that only two processes can access the resource at a time even though more than two can request it at a time. (Note that what goes inside AccessResource is irrelevant to your assignment. Your job is to make sure that at most two of them can access it at a time)
1. Solve this problem using testset instruction. This solution may use busy waiting and does not have to guarantee fairness.
2. Solve this problem using semaphores. This solution may not use busy waiting and has to guarantee fairness.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.