Chapter 7 Flashcards
What are some Concurrency Issues?
Memory contention. Contention for communication medium. Communication latency
What is memory contention
Not all processors can access the same memory at the same time. if they try they will have to queue
what is “Contention for Communication medium”
If everyone wants to communicate at the same time some of them will have to wait
what is communication latency?
time it takes for info to be transmitted from 1 part of system to another
What should a thread do if it cant get a lock
Keep trying (spinning/busy-wait)
Give Up the processor (suspend and reschedule to create another thread on processor)
When is Thread suspension good?
When a uniprocessor is used.
If delays are long
What is contention?
When multiple threads try to acquire a lock at the same time
What is the problem with Filter/Bakery Locks?
need to write n distinct locations (n concurrent threads). Lock requires space linear in n
What is the problem with the Peterson lock
We assumed that read and write operations are atomic.
our proof relied on assumption that any 2 memory accesses (by same thread) will take place in program order
what is the problem with memory barriers
they are expensive
Which Synchronization instructions usually include memory barriers
getAndSet() or compareAndSet()
Do reads + writes to volatile fields include memory barriers?
yes
What does Test-and-Set do
Swap true with current value
return value tells if prior value was true or false. can reset by writing false. AKA getAndSet
Code for Test-and-Set
public synchronized boolean
getAndSet(boolean newValue) {
boolean prior = value;
value = newValue;
return prior;
}
When is a Test-and-Set taken and free?
if value = false, lock = free. else lock is taken (true = taken, free = false)