Question: 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
Get step-by-step solutions from verified subject matter experts
