COS3721 ASSIGNMENT 2 SOLUTIONS 2021
QUESTION 1 Deadlock
2.1 Assume that a multithreaded application uses only reader–writer locks for
synchronization. Applying the four necessary conditions for deadlock, is deadlock still
possible if multiple reader–writer locks are used?
Yes when applying the four deadlock conditions for a deadlock , the deadlock is still
possible. If multiple readers as follows :
1. Mutual exclusion is maintained, as they cannot be shared if there is a writer.
2. Hold-and-wait is possible, as a thread can hold one reader writer lock while waiting to
acquire another.
3. You cannot take a lock away, so no preemption is upheld.
4. A circular wait among all threads is possible.
2.2 Consider the following snapshot of a system:
Allocation Max
ABCD ABCD
T0 1 2 0 2 4 3 1 6
T1 0 1 1 2 2 4 2 4
T2 1 2 4 0 3 6 5 1
T3 1 2 0 1 2 6 2 3
T4 1 0 0 1 3 1 1 2
QUESTION 1 Deadlock
2.1 Assume that a multithreaded application uses only reader–writer locks for
synchronization. Applying the four necessary conditions for deadlock, is deadlock still
possible if multiple reader–writer locks are used?
Yes when applying the four deadlock conditions for a deadlock , the deadlock is still
possible. If multiple readers as follows :
1. Mutual exclusion is maintained, as they cannot be shared if there is a writer.
2. Hold-and-wait is possible, as a thread can hold one reader writer lock while waiting to
acquire another.
3. You cannot take a lock away, so no preemption is upheld.
4. A circular wait among all threads is possible.
2.2 Consider the following snapshot of a system:
Allocation Max
ABCD ABCD
T0 1 2 0 2 4 3 1 6
T1 0 1 1 2 2 4 2 4
T2 1 2 4 0 3 6 5 1
T3 1 2 0 1 2 6 2 3
T4 1 0 0 1 3 1 1 2