Skip to content
Snippets Groups Projects
Commit ede019ea authored by antux18's avatar antux18
Browse files

t3.

parent d6d6a642
Branches
No related merge requests found
# Task 3
The problem is that each thread is unlocking a mutex it didn't unlock.
\ No newline at end of file
The problem that can occur is that each thread is trying to lock a mutex locked by the other thread. And each time they fail, they unlock their own locked mutex and then lock it again in the next iteration. Each process is actively locking and unlocking their own mutex while trying to get the other's mutex. So each of the threads might end up acquiring one of the 2 resources they need while the other one is still held, failing over and over to acquire both resources in a limited amount of time. This is a livelock.
A way to solve this issue would be to put the locking of both mutexes in a critical section, so that each thread is assured to get both of the mutexes, or none, thus avoiding the other thread to get stuck because one of its required mutexes is locked by another thread (same as the problem of the philosophers).
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment