Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:
/* thread_one runs in this function
void *do_work_one(void *param){
pthread_mutex_lock(&first_mutex);
pthread_mutex_lock(&second_mutex);
/* do some work */
pthread_mutex_unlock(&second_mutex);
pthread_mutex_unlock(&first_mutex);
}
/* thread_two runs in this function */
void *do_work_two(void *param){
pthread_mutex_lock(&second_mutex);
pthread_mutex_lock(&first_mutex);
/* do some work */
pthread_mutex_lock(&first_mutex);
pthread_mutex_lock(&second_mutex);
pthread_exit();
}
In which scenario would deadlock occur?
The following program does not always lead to deadlock:
/* thread_one runs in this function
void *do_work_one(void *param){
pthread_mutex_lock(&first_mutex);
pthread_mutex_lock(&second_mutex);
/* do some work */
pthread_mutex_unlock(&second_mutex);
pthread_mutex_unlock(&first_mutex);
}
/* thread_two runs in this function */
void *do_work_two(void *param){
pthread_mutex_lock(&second_mutex);
pthread_mutex_lock(&first_mutex);
/* do some work */
pthread_mutex_lock(&first_mutex);
pthread_mutex_lock(&second_mutex);
pthread_exit();
}
In which scenario would deadlock occur?
If thread_one acquires both locks before thread_two.
If thread_two acquire both locks before thread_one.
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago