Locking Flashcards

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

What are the two statuses a lock can have?

A

Available & acquired

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
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
4
Q

Give the function call: Releases the lock thathas been acquired by caller

A

unlock()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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
6
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
6
Q
A
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: overhead to grad & release lock

A

Performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
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
10
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
11
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
12
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
13
Q

What is the advantage of using a simple spinlock?

A

Mutual exclusion

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

What are the two disadvantages with using a simple spinlock?

A

No fairness & no performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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

A

Ticket lock

16
Q

What does a ticket lock guarantee?

17
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

18
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

19
Q

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?

A

Spinning is wasteful

20
Q

Give the definition of the function call:
Instead of spinning, the CPU is given up to another process/thread. The yielding thread deschedules itself.

21
Q

Give the definition of the spinlock type:
Sleep and put thread on a queue instead of spinning

A

Locks with queue

22
Q

What do locks with queue guarantee won’t happen as long as all threads relinquish locks

A

Starvation

23
Q

Give the definition of the spinlock type:
Hybrid approach that combines both spin-wait & sleep/block

A

Two phase lock

24
Q

Is the lock released quickly or slowly with spin-wait?

25
Q

Is the lock released quickly or slowly with sleep/block?

26
Q

Is this the first or second phase of a two phase lock?
The lock spins for a while

27
Q

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

28
Q

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.

A

Adaptive mutex