Synchronization Flashcards

1
Q

What is atomic exchange?

A

EXCH R1, 78(R2) - swaps the two values in R1 and the mem location in 78(R2).

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

How do you implement a lock with atomic exchange?

A

R1 = 1

While (R1 == 1) EXCH R1, lockvar

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

What is the drawback to atomic exchange?

A

You are constantly writing

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

Test-and-write impl?

A

look up

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

What are the cons of atomic EXCH and test-write?

A

Since they are performing a load and a store for a single instruction, they are really bad for pipelining => would need to add another memory stage just to deal with atomic instructions

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

How does a load linked instruction work?

A

Behaves just like a normal load, plus it stores the address in a link register. Replaces the ‘read’ of an atomic instruction

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

What does a store conditional instruction work?

A
  1. Checks if its computed address is the same as the one in the link register
  2. If same => normal store, return 1
  3. Else => return 0 (no store)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How is LL/SC atomic?

A

Must rely on snooping all writes to lockvar (our load link addr). If we snoop a write, we put 0 in the link register. AKA we rely on coherence to ensure it is atomic

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

How can LL/SC be used to make small critical sections more efficient?

A

Can use them instead of a lock, since it is storing a variable atomically

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

LL, R1, MEM

A

Load MEM to R1, store MEM in link register

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

SC R1, MEM

A

Store R1 to MEM. If success, R1 = 1, else R1 = 0

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

What is barrier synchronization?

A

Barrier ensures that all threads must have reached the barrier, before any can leave it.

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

What is need for a barrier synchronization implementation?

A

Counter (n threads)

flag (set when counter = n)

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

Why is a simple barrier implementation not reuseable?

A

If a core cannot read the flag variable=1 fast enough, another core can reset it back to 0 and the first core will spin indefinitely (and block the other threads too since it will never re-reach the barrier)

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

How do we implement reusable barriers?

A

Switch the flag each time (i.e the value that we are waiting for should switch)

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