Slides 9 Flashcards
Define Deadlock
a state where each process/thread is waiting on another to release a lock → no progress is made
Define Livelock
states of the processes change, but none are progressing
Define starvation
one process does not get to run at all
Define unfairness
not all processes get equal opportunity to progress
What is the dining philosopher problem?
before eating, a philosopher must first grab two forks, immediately to the left & right
• philosopher then eats for a short time
• when done eating, the philosopher puts
down the forks in their original positions
• philosopher then thinks for a short time
What are important facts about mutex’s?
mutex is a synchronization mechanism used for
ensuring exclusive access to a resource in concurrent programs
• we can set it to True or False, just like a regular boolean variable
• but, if the lock is already locked, and some thread tries to also lock it,
then the calling thread will be automatically suspended… until whoever locked the lock unlocks it
only the thread that locks the mutex can unlock it
• a waiting queue is used to keep track of all threads waiting on
the mutex to be unlocked
• once the mutex is unlocked, one of the blocked threads will be
unlocked…
• note: which one thread gets unlocked is usually not predictable
What are the mutex methods?
phread_mutex_init(): creates mutex
phread_mutex_destroy(): destroys mutex
phread_mutex_lock(): locks mutex, block if already locked
phread_mutex_trylock(): lock a mutex or fail(non-blocking version)
phread_mutex_unlock(): unlock mutex