Question: Given the following program, what, if anything should be done? #include #include #include #include using namespace std; mutex mtx 1 , mtx 2 ; void
Given the following program, what, if anything should be done?
#include
#include
#include
#include
using namespace std;
mutex mtxmtx;
void john
for auto i:
mtxlock;
thisthread::sleepforchrono::milliseconds;
mtxlock;
cout "John has the locks" endl;
mtxunlock;
mtxunlock;
void jane
for auto i:
mtxlock;
thisthread::sleepforchrono::milliseconds;
mtxlock;
cout "Jane has the locks" endl;
mtxunlock;
mtxunlock;
int main
auto t threadjohn;
auto t threadjane;
tjoin;
tjoin;
Group of answer choices
void jane
for auto i:
mtxlock;
cout "Jane has the lock" endl;
mtxunlock;
NEVER USE TWO MUTEXES together, so remove mtx
void jane
for auto i:
lock mtx mtx;
cout "Jane has the locks" endl;
Because lock automatically unlocks when it goes out of scope.
void jane
for auto i:
mtxlockmtx;
cout "Jane has the locks" endl;
mtxunlock;
mtxunlock;
Because mtx will not lock until it locks mtx
void jane
for auto i:
lock mtx mtx;
cout "Jane has the locks" endl;
mtxunlock;
mtxunlock;
Because lock does not acquire the locks until it can get both.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
