Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1_ The program example shown down doesn’t always lead to deadlock. Describe what

ID: 3822485 • Letter: 1

Question

1_ The program example shown down doesn’t always lead to
deadlock. Describe what role the CPU scheduler plays and how it can
contribute to deadlock in this program.

/* 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);
pthread exit(0);
}
/* 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 unlock(&first mutex);
pthread mutex unlock(&second mutex);
pthread exit(0);
}

2_Consider a system consisting of four resources of the same type that are
shared by three processes, each of which needs at most two resources.
Show that the system is deadlock free.

3_ Consider the version of the dining-philosophers problem in which the
chopsticks are placed at the center of the table and any two of them
can be used by a philosopher. Assume that requests for chopsticks are
made one at a time. Describe a simple rule for determining whether a
particular request can be satisfied without causing deadlock given the
current allocation of chopsticks to philosophers.

Explanation / Answer

1 . In the given program the deadlock occurs if and only if one of the thread_one or thread_two will acquire only one lock before the other thread acquires second lock. And the program does not leads to deadlock if the thread_one will be scheduled before thread_two , and the thread_one acquired both mutex locks before the schedule of thread_two .

2. The given system will not contain a deadlock because , in the system there are 4 resources and 3 processes , if a process will consists of two resources , it will not require any other resource and it returns the resources after completion , hence the system is deadlock free.

3. In the given system If a philosopher requests for a first chopstick , do not satisfy the request only if no other philosopher has 2 chopsticks and if there is only 1 chopstick remaining.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote