Chapter 7 Flashcards

1
Q

What are some Concurrency Issues?

A

Memory contention. Contention for communication medium. Communication latency

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

What is memory contention

A

Not all processors can access the same memory at the same time. if they try they will have to queue

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

what is “Contention for Communication medium”

A

If everyone wants to communicate at the same time some of them will have to wait

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

what is communication latency?

A

time it takes for info to be transmitted from 1 part of system to another

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

What should a thread do if it cant get a lock

A

Keep trying (spinning/busy-wait)
Give Up the processor (suspend and reschedule to create another thread on processor)

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

When is Thread suspension good?

A

When a uniprocessor is used.
If delays are long

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

What is contention?

A

When multiple threads try to acquire a lock at the same time

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

What is the problem with Filter/Bakery Locks?

A

need to write n distinct locations (n concurrent threads). Lock requires space linear in n

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

What is the problem with the Peterson lock

A

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

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

what is the problem with memory barriers

A

they are expensive

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

Which Synchronization instructions usually include memory barriers

A

getAndSet() or compareAndSet()

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

Do reads + writes to volatile fields include memory barriers?

A

yes

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

What does Test-and-Set do

A

Swap true with current value
return value tells if prior value was true or false. can reset by writing false. AKA getAndSet

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

Code for Test-and-Set

A

public synchronized boolean
getAndSet(boolean newValue) {
boolean prior = value;
value = newValue;
return prior;
}

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

When is a Test-and-Set taken and free?

A

if value = false, lock = free. else lock is taken (true = taken, free = false)

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

how do you know if you have the Test-and-Set lock

A

If the result is false (previous value was false)

17
Q

how to release a TAS lock?

A

simply write false
void unlock() {
state.set(false);
}

18
Q

Why is TAS Bad

A

Many threads spin = wasted CPU resources. Also doesnt guarantee fairness

19
Q

What does cache hit and cache miss mean

A

hit = found. miss = have to go look in memory

20
Q

What are the “stages” of a Test-and-Test-and-Set lock?

A

Lurking stage. pouncing stage

21
Q

what is the lurking stage in a TTAS?

A

wait until lock looks free
spin while read returns true (lock taken

22
Q

what is the pouncing stage in a TTAS

A

as soon as lock looks available
read returns false (lock = free)
Call TAS to acquire lock
If TAS loses = back to lurking

23
Q

what is good about the TTAS?

A

A acquires lock
1st time B reads lock = cache miss + use bus to get new value
as long as A holds B rereads same value (cache hit every time)
B != extra traffic

24
Q

What is Bad about TTAS

A

If A releases and writes false to lock variable all spinners cache is invalidated. each takes cache miss to read new value using bus.
all call getAndSet() to aquire lock
after 1st one gets lock all other caches invalidated again

25
Q

Basic explanation of Exponential Backoff

A

If I see that the lock is free, but then another thread acquires it before I can, then there must be high contention for that lock. backoff and try again later. larger number of unsuccessful tries = higher contention = longer backoff needed

26
Q

In a Exponential backoff should the backoff times be random?

A

Yes. else everyone backs off the same amount of time

27
Q

When is a Back off triggered?

A

Only when a lock was just free but we couldnt get it

28
Q

Why is a backoff lock good?

A

Easy to implement
beats TTAS lock

29
Q

Why is a backoff lock bad

A

Parameters must be chosen carefully
it is sensitive to number of processors + their speeds

30
Q

Backoff lock drawbacks

A

all threads spin on same location
CS underutilization:
threads delay longer than necessary

31
Q

Why are queue locks good?

A

Fair. Cache-coherence traffic is reduced. Increase Critical section utilization

32
Q

What is good/Bad about Anderson Queue lock

A

Scalable. Easy to implement
Not space efficient. 1 bit per thread

33
Q

Basic CLH queue Lock explination

A

Virtual Linked List to keep track. Each thread’s status is saved in its node (true = has/wants to acquire lock. false = finished + released. Each node keeps track of its predecessors status

34
Q

How do Composite Locks work?

A

Keep small number of waiting threads in a queue. rest exponential backoff

35
Q

How do threads try to acquire a lock in CL?

A

each thread selects a node in array at random. if node is in use, thread backs off and tries again. If node is acquired = enqueues in TOLock style queue

36
Q

What are the states of the nodes in the array?

A

FREE, WAITING, RELEASED, ABORTED. FREE = available for other threads. WAITING = linked into queue to apply for CS. can also be inside CS.

37
Q

How does a thread acquire a lock in the Composite Lock?

A

Acquire node in waiting array.
Enqueues node in queue
Wait until head of queue