Untitled Deck Flashcards
(14 cards)
What is granularity?
Size of code blocks you’re protecting
What is fine grained? What protection is typically used?
Smaller blocks of code, protected by lock free approach
What is coarse grained? What protection is typically used?
Larger blocks of code, protect by mutex lock
Name two types of concurrency
Message passing concurrency, shared memory concurrency
What 3 advantages are there for message passing over shared memory?
1) Lower risk of deadlock 2) Avoid problems with cache visibility 3) Don’t need to think about mutex locks
What 2 disadvantages are there for message passing over shared memory?
1) slower 2) hard to ensure global consensus
Why was Peterson’s algorithm introduced?
Give mutual exclusion
What sort of architecture is Peterson’s thread safe on?
Single processor architecture, there’s no instruction reordering
What sort of architecture is Peterson’s NOT thread safe on?
Modern architecture, there’s instruction reordering
If flag(process) comes before turn = process, Peterson’s is thread safe. What if it was switched?
IF these two lines were swaped and context switched between them, it would no longer be thread safe
If turn = process comes before flag(process), it is not thread safe. What could be added to fix this?
A memory barrier after these two lines would ensure mutex. It would ensure both happen and flush memory.
What is compare and set?
It’s an atomic expression (comparing and setting are done in one instruction)
What are the 3 inputs for compare and set?
1) An address to look at 2) Old value you’re expecting at address 3) New value for the address
What does compare and set do? 5 steps
1) Check value at address 2) Compare with expected value 3) If valid (they match) replace 4) if not valid (don’t match) do not replace 5) Return boolean depending on operation success