CH 08
CH 08
Threads – active
Resources – passive, things needed by thread to do its job
CPU, disk space, memory
P0 P1
wait (A); wait(B);
wait (B); wait(A);
Signal(B); signal(A);
Signal(A); Signal(B);
Pi requests instance of Rj
Pi
Rj
Pi is holding an instance of Rj
Pi
Rj
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);
}
Need Available
ABC ABC
P0 743 332
P1 122
P2 600
P3 011
P4 431
The system is in a safe state since the sequence < P1, P3,
P4, P2, P0> satisfies safety criteria
Detection algorithm
Recovery scheme
Resource-Allocation Graph
Corresponding wait-for graph
Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for
all i
State of system?
Can reclaim resources held by process P0, but
insufficient resources to fulfill other processes’ requests
Deadlock exists, consisting of processes P1, P2, P3, and
P4