ch.6 Synchronization Flashcards
what is a race condition
TIMING -> the outcome of the program depends on which thread or process finishes execution first or the specific timing of certain events
what are the two most common concurrency bugs?
atomicity violation, data race
what is an atomicity violation?
when a thread has not finished updating a variable but another thread reads the non updated version
what is a data race?
when two unordered memory operations act on the same variable one of which is a write
what are critical sections?
- the section must be execute by only one thread at a time
- part of the program that must be atomic
what are the four requirements for mutual exclusion?
- no two threads can be in the critical section at the same time
- there can be any number of threads
- no thread that is outside of the critical region can block another thread
- no thread can wait forever
what is the starvation property
every thread must get a turn to execute
how do semaphores work in a bounded buffer?
look at synchronization notes
what do semaphores up / down functions do?
atomically increment or decrement a value ( does not busy wait)
what are locks?
gives possession of each critical section (ensuring that only one thread is in the CS)
what are two main function of locks and what do they do?
acquire grabs the lock and gain access to the CS and release() gives up access to the CS
what do condition variables do?
allow for threads to sleep while waiting for a lock
- if a lock is not available then it will give up the lock and sleep until it is signaled to wake up again