Question: The code example below lead to deadlock between two threads. I * * thread _ one runs in this function * * ? void *
The code example below lead to deadlock between two threads.
threadone runs in this function
void doworkonevoid param
pthreadmutexlock&first mutex;
pthreadmutexlock&secondmutex;
Do some work
pthreadmutex unlock &second mutex;
pthreadmutexunlock&first mutex;
pthreadexit ;
threadtwo runs in this function
void do work twovoid param
i
pthread mutex lock &second mutex;
pthreadmutexlock&firstmutex;
Do some work
I
pthread mutex unlock &first mutex;
pthread mutex unlock &second mutex;
pthread exit ;
will not
can
always
will
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
