Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Deadlock The bank decides to use fine-grained locking. Here is its implementation: // assume all the variables are initialized correctly double balance [2]; //
2. Deadlock The bank decides to use fine-grained locking. Here is its implementation: // assume all the variables are initialized correctly double balance [2]; // @for alice, 1 for bob smutex_t mtx[2]; // for alice, 1 for bob bool transfer(int from, int to, double trans) { smutex_lock(&mtx[from]); smutex_lock(&mtx[to]); bool result = false; if (balance[from] > trans) { balance[from] = balance[from] - trans; balance[to] = balance[to] + trans; result = true; } smutex_unlock(&mtx[to]); smutex_unlock(&mtx[from]); return result; } 2.1. Write down an interleaving that results in deadlock. 2.2. Keeping the same data structures, rewrite transfer() to eliminate the possibility of deadlock
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started