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

Mutexes and Threads Order these function calls between Threads T and U contained

ID: 3831677 • Letter: M

Question

Mutexes and Threads Order these function calls between Threads T and U contained in Process P in such a way that when USB Device U is connected. it causes "CONNECTED to be written to a data file, with the threads arranging themselves to wnite the same again the next time the device is connected. Note: Process P contains two variables that are shared among all threads: Mutex M (initially with no locks) and Bool B (initially set to false). Drag and drop to order A USB Device U is connected to the computer, setting Bool B equal to true. Meanwhile, Thread U writes "CONNECTED to the data file and then terminates. USB Device U is disconnected from the computer. Thread T creates Thread U inside Process P Thread T pauses until Bool B equals true. D Meanwhile, Thread U calls lock0 on Mutex M. E Thread T calls lock0 on Mutex M. Thread T resumes execution. Thread T sets Bool B equal to false. Thread T calls unlock() on Mutex M. Thread T calls join(), targeting Thread U

Explanation / Answer

1 USB Device U is connected to the computer, setting Bool B equal to true.

2 process p creates thread t

3 Thread T creates Thread U inside Process P Thread T pauses until Bool B equals true.

4 Thread T calls lock0 on Mutex M.

5 Meanwhile, Thread U calls lock0 on Mutex M

6 Thread T resumes execution. Thread T sets Bool B equal to false.

7 Thread T calls unlock() on Mutex M. Thread T calls join(), targeting Thread U

8 thread t returns to the second step above

9 Meanwhile, Thread U writes CONNECTED to the data file and then terminates. USB Device U is disconnected from the computer.

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