Lesson 4b Flashcards

Parallel Systems

1
Q

What is a mutex

A

Mutual exclusion lock. Only one thread can access

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

What is a semaphore

A

A shared lock multiple threads can access data “Multiple readers”

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

Barrier Synchronization?

A

You have a location that other threads will wait for until all of them reach the location “Host wait until everyone is at the restaurant”

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

Atomic Instructions

A

Load-and-store, read-and-inc, etc…

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

What is all that is needed from the instruction set for barrier sync?

A

atomic read and write

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

what is rmw instruction?

A

Read-Modify-Write. Needed to set a value that is also being checked. If(i == 0) i = 1; this needs to happen atomically.

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

Different types of RMW

A

Test-and-set, Fetch-and-inc, fetch-and-0

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

Scalability issue with barrier sync

A

latency, waiting time, contention

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

What is spin lock on test and set?

A

if locked){while(locked){…} locked = 1; /* testAndSet in the while condition */

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

what is spin on read?

A

waiters spin on cached copy of L. Doesn’t create contention on network. /Checking local cache/ while(L == locked){ if (test-and-set(L) == locked) go back

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

How do we avoid contention when a lock is released

A

spin lock with delay

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

Can all processors have the same delay value?

A

No, this will cause the same contention that working from a regular spin lock would cause

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

What happens with delay that has exponential backoff

A

On each lock in the while loop the length of the delay is doubled. While(TestAndSet(L) == locked){ delay(d); d = d * 2; }

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

What is an important problem with spin lock?

A

Fairness, spin lock doesn’t guarantee that the original requester will get the lock first

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

what is the ticket lock similar to in daily life?

A

A ticket system at the deli. If you get ticket 16 you have to wait from stay ticket 5 until 16. Anyone that comes after you will need to wait to order.

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

What is the structure of the ticket lock?

A

struct lock { int next_ticket; int now_serving; };

17
Q

What is the ticket algo

A

int myticket = fetchAndInc(l->next_ticket) loop {pause(my_ticket - l->now_serving); if (now_serving == my_ticket) return;
release_lock(L)
l->now_serving++; /* why is this happening after the lock? */

18
Q

What causes network contention for ticket locks?

A

updating the “now_serving” global var. That causes caches to need updating

19
Q

Key points of array based queuing lock?

A

Each processor gets the next available slot in the array. But the slots are not statically assigned to a Process.

20
Q

What is the size of the queue array in a queuing lock?

A

It is the size of the number of processors

21
Q

What are the two states in the queuing array?

A

has-lock and must-wait

22
Q

What is the name of the variable that keeps track of the queue location?

23
Q

What problem does the queue lock solve

A

It is fair and it is not noisy. CPU cache will not need to be invalidated

24
Q

what are the downsides of queue lock?

A

Space, if you have 1000 CPUs then you are eating into memory space

25
How would you solve the size problem of the queue lock?
use dynamic allocation (linked-list)
26
What ins(opcode) is required for the linked based queueing lock
fetch-and-store. It is required for fixing the list atomically
27
How can a race condition be avoided when unlocking a queue linked-list
compare-and-swap (L, me, nil) compare 1st and 2nd set 1st and 3rd.
28
How would comp-and-swap be implemented
gcc has some builtin for these
29
How do you add a new waiter to the linked queue
Set last requester next to the new waiter. Set current running next to new waiter, This breaks the connection from last to current
30
What is the lock algo for the linked queue
- Join L atomically (fetch-and-store), - await predecessor to signal spin