Locking Flashcards
(43 cards)
⭐️ What is the objective of a lock?
To provide mutual exclusion
⭐️ A lock is a variable (T/F)
True
⭐️ What are the two states a lock can have?
Available/free & Locked/held
⭐️ Give the function call: Tries to acquire the lock
lock()
⭐️ Give the function call: Releases the lock that has been acquired by caller
unlock()
What are the three attributes that a good lock has?
Mutual exclusion, fairness and performance
What attribute of a good lock has the following description: progress & ensures no starvation
Fairness
What attribute of a good lock ensures correctness?
Mutual exclusion
What attribute of a good lock has the following description: overhead to grad & release lock
Performance
⭐️ What is a software-based solution to locking that’s used for loads & stores?
A single flag variable
⭐️ What are possible issues with the single flag variable for loads & stores solution in locking?
Not atomic - No MutEx
Performance overhead
What do we call the software based solution to the critical section problem?
Peterson’s Solution
⭐️ What’s the hardware based solution for locking that ensures mutual exclusion & atomic execution?
Test-And-Set
⭐️ Give the definition of the instruction:
Tests and modifies the content of a memory word atomically
TestAndSet (TAS)
Give the definition of the instruction:
Tests whether the value at the address specified by ptr is equal to expected, if so, updates the memory location pointed to by ptr with the new value
Compare-And-Swap
⭐️ Give the definition:
A lock that spins, using CPU cycles, until the lock becomes available
Spinlock
⭐️ Give the definition:
When a thread needs to endlessly check the lock value to check if the lock is held by others
Spin-waiting
⭐️ What is the advantage of using a simple spinlock?
Mutual exclusion
⭐️ What are the two disadvantages with using a simple spinlock?
No fairness & poor performance
What lock type does the following:
Locks
1. Uses Fetch-And-Add on the ticket value
2. Return value is the threads “turn” value
Unlocks
1. Increments the turn
Ticket lock
What does a ticket lock guarantee?
Fairness
Ticket locks ensure that there’s no
Starvation
Give the definition of the hardware primitive: Atomically increments a value while returning the old value at a particular address
Fetch-And-Add
Spinlocks can be fast when there are:
- Many CPUs
- Locks are held a short time
What is the advantage that makes a spinlock fast in this case?
No context switch