chapter 29: lock-base concurrent data structures Flashcards

1
Q

how to make a data structure thread safe?

A

add locks to it

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

which 4 data structures are covered?

A

counters, linked list, queues, hash tables

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

how to make counter concurrent?

A

simply add a lock. lock - action - unlock
actions: increment, decrement, get
whenever a value is changed. Critical section

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

whats wrong with the approach above?

A

Performance. having 2 threads each update the counter 1 million times concurrently leads to a MASSIVE slowdown. it gets worse with more threads.

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

what is perfect scaling?

A

threads complete just as quickly on multiple processors as the single thread does on one.

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

how can we create scalable counting?

A

sloppy counter.

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

how does sloppy counter work? and how does the size of S(threshold) affect the scalability?

A

representing a single logical counter via numerous local physical counters, one per CPU core, as well as a single global counter. a lock for each local counter and a lock for global counter.
how it works?
local counter counts for each one and because they are seperate, there is no slowing down.
local values are then periodically updated to global counter by acquiring global lock and incrementing it. local counter then set to 0.
how often it is updated is determined by S(threshold)
smaller S, less scalable
bigger S, global lags behind

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

how well does sloppy counter work in terms of scalability?

A

excellent, hardly higher than one processor.

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

key features of locking linked list?

A

lock critical section, also remember if there is error you unlock there too.
lock is called once.
unlock called twice, one error, one no error

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

how to scale linked list?

A

hand-over-hand locking

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

what is hand-over-hand locking?

A

add a lock per node of the list.
when traversing the list, first grabs next node’s lock and then release current node’s lock.
high degree of concurrency but low performance
too many locks -> slow

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

Michael and scott concurrent queue approach

A
2 locks. 
headlock for dequeue
taillock for enqueue
dummy node enables the separation of head and tail operation
related to CV
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

concurrent hashtable - simple hashtable that does not resize

A

lock per hash bucket

concurrent hashtable scales magnificently!

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

correctness first performance after

A

rule

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