Locking Flashcards

(43 cards)

1
Q

⭐️ What is the objective of a lock?

A

To provide mutual exclusion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

⭐️ A lock is a variable (T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

⭐️ What are the two states a lock can have?

A

Available/free & Locked/held

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

⭐️ Give the function call: Tries to acquire the lock

A

lock()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

⭐️ Give the function call: Releases the lock that has been acquired by caller

A

unlock()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the three attributes that a good lock has?

A

Mutual exclusion, fairness and performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What attribute of a good lock has the following description: progress & ensures no starvation

A

Fairness

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What attribute of a good lock ensures correctness?

A

Mutual exclusion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What attribute of a good lock has the following description: overhead to grad & release lock

A

Performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

⭐️ What is a software-based solution to locking that’s used for loads & stores?

A

A single flag variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

⭐️ What are possible issues with the single flag variable for loads & stores solution in locking?

A

Not atomic - No MutEx
Performance overhead

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do we call the software based solution to the critical section problem?

A

Peterson’s Solution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

⭐️ What’s the hardware based solution for locking that ensures mutual exclusion & atomic execution?

A

Test-And-Set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

⭐️ Give the definition of the instruction:
Tests and modifies the content of a memory word atomically

A

TestAndSet (TAS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

Compare-And-Swap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

⭐️ Give the definition:
A lock that spins, using CPU cycles, until the lock becomes available

A

Spinlock

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

⭐️ Give the definition:
When a thread needs to endlessly check the lock value to check if the lock is held by others

A

Spin-waiting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

⭐️ What is the advantage of using a simple spinlock?

A

Mutual exclusion

19
Q

⭐️ What are the two disadvantages with using a simple spinlock?

A

No fairness & poor performance

20
Q

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

21
Q

What does a ticket lock guarantee?

22
Q

Ticket locks ensure that there’s no

23
Q

Give the definition of the hardware primitive: Atomically increments a value while returning the old value at a particular address

A

Fetch-And-Add

24
Q

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?

A

No context switch

25
Spinlocks can be slow when there is: - One CPU - Locks are held a long time What is the disadvantage that makes a spinlock slow in this case?
Spinning is wasteful
26
Give the definition of the function call: Instead of spinning, the CPU is given up to another process/thread. The yielding thread deschedules itself.
yield()
27
Give the definition of the spinlock type: Sleep and put thread on a queue instead of spinning
Locks with queue
28
What do locks with queue guarantee won't happen as long as all threads relinquish locks
Starvation
29
Queue locks ensure predictable order (T/F)
True
30
⭐️ Give the definition of the spinlock type: Hybrid approach that combines both spin-wait & sleep/block
Two phase lock
31
⭐️ Is the lock released quickly or slowly with spin-wait?
Quickly
32
⭐️ Is the lock released quickly or slowly with sleep/block?
Slowly
33
⭐️ Is this the first or second phase of a two phase lock? The lock spins for a while
First
34
⭐️ Is this the first or second phase of a two phase lock? If the lock is acquired in the first phase, put the calling thread to sleep
Second
35
Give the definition of the spinlock type: If a thread has a locked adaptive mutex and the process/thread holding the adaptive mutex is running, the adaptive mutex executes busy waiting. Otherwise, it blocks the thread.
Adaptive mutex
36
⭐️ What's a spinlock? 1. A lock that repeatedly checks if the lock is available 2. A lock that puts the thread to sleep until the lock is available 3. A lock that allows multiple threads to access a resource simultaneously 4. A lock that prevents deadlocks
1.
37
⭐️ What's the main disadvantage of using a spinlock? 1. It can lead to deadlocks 2. It wastes CPU resources while waiting 3. It cannot be used in multithreaded programs 4. It's slower than a mutex
2.
38
⭐️ Spinlocks are starvation free. (T/F)
False
39
What are the three metrics to evaluate locks?
Correctness Fairness Performance
40
⭐️ Ticket locks ensure that threads acquiring the lock grab it in FIFO order (T/F)
True
41
⭐️ Which hardware primitive is used to implement the ticket lock? TestAndSet CompareandSwap FetchAndAdd
FetchAndAdd
42
⭐️ Spinlocks are always slow because of the busy-waiting (T/F)
False; they can be fast if the critical sections are short
43
⭐️ What's the purpose of calling yield() inside a spinlock implementation? 1. To release the spinlock and allow another thread to acquire it 2. To wake up another thread that's waiting for acquiring the spinlock 3. To voluntarily give up the CPU, mitigating busy-waiting 4. To add the calling thread to the waiting queue
3.