Question: The following program does not always lead to deadlock: / * thread _ one runs in this function void * do _ work _ one
The following program does not always lead to deadlock:
threadone runs in this function
void doworkonevoid param
pthreadmutexlock&firstmutex;
pthreadmutexlock&secondmutex;
do some work
pthreadmutexunlock&secondmutex;
pthreadmutexunlock&firstmutex;
threadtwo runs in this function
void doworktwovoid param
pthreadmutexlock&secondmutex;
pthreadmutexlock&firstmutex;
do some work
pthreadmutexlock&firstmutex;
pthreadmutexlock&secondmutex;
pthreadexit;
In which scenario would deadlock occur?
The following program does not always lead to deadlock:
threadone runs in this function
void doworkonevoid param
pthreadmutexlock&firstmutex;
pthreadmutexlock&secondmutex;
do some work
pthreadmutexunlock&secondmutex;
pthreadmutexunlock&firstmutex;
threadtwo runs in this function
void doworktwovoid param
pthreadmutexlock&secondmutex;
pthreadmutexlock&firstmutex;
do some work
pthreadmutexlock&firstmutex;
pthreadmutexlock&secondmutex;
pthreadexit;
In which scenario would deadlock occur?
If threadone acquires both locks before threadtwo.
If threadtwo acquire both locks before threadone.
If one thread is able to acquire only one lock before the other thread acquires the second lock.
All of the above
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
