Which Condition Falls

/* thread 1 */                  /* thread 2 */
pthread_mutex_lock(&L1);        pthread_mutex_lock(&L2);
pthread_mutex_lock(&L2);        pthread_mutex_lock(&L1);
/* ... */                       /* ... */

Deadlock requires all four of mutual exclusion, hold-and-wait, no preemption, and circular wait. Select every change below that makes deadlock impossible for this code. More than one applies.

A

Hold a single global prevention mutex across both acquisitions in both threads.

B

Shorten both critical sections so the vulnerable window is only a few nanoseconds.

C

Have both threads acquire the two mutexes in increasing address order.

D

Replace the second acquisition with pthread_mutex_trylock, and on failure release the first lock and restart the sequence.

E

Replace both mutexes with recursive mutexes.