I'm not sure if my answers to the following exercise is correct:
Suppose the program is run with two threads. Further suppose that the following sequence of events occurs:
Time Thread 0 Thread 1 0 pthread_mutex_lock(&mut0) pthread_mutex_lock(&mut1) 1 pthread_mutex_lock(&mut1) pthread_mutex_lock(&mut0)
b. Would this be a problem if the program used busy-waiting (with two flag variables) instead of mutexes?
c. Would this be a problem if the program used semaphores instead of mutexes?
Are the outcomes for this not the exact same in that they'd result in a deadlock?
For b) if we use a spinlock, the outcome would look something like this, right? (Let
flag0 = flag1 = 1)
Time Thread 0 Thread 1 0 flag0--; flag1--; 1 while(flag1 == 0); while(flag2 == 0);
For c) I'm assuming they're referring to a binary semaphore, which is effectively the same thing as a mutex so it'd also result in deadlock.
Is there a mistake in my reasoning? My answers seem suspiciously simple but I don't see how spinlock/semaphores would change anything