Unbounded Lock free stack Flashcards

1
Q

Is an unbounded Lock free stack atomic?

A

Yes. Lock free = atomic

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

What methods does it use to change the link values in the list?

A

compareAndSet

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

Give the code to tryPush code

A

public boolean tryPush(Node node){
Node oldTop = top.get();
node.next = oldTop;
return(top.compareAndSet(oldTop, node))
}

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

When does the tryPush return false?

A

When another thread has already modified the top. There is high contention

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

When is it better to use a backoff?

A

when there is high contention

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

Give the push function code

A

public void push(T value) {
Node node = new Node(value);
while (true) {
if (tryPush(node)) {
return;
} else backoff.backoff();
}}

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

Give the code for the pop function

A

public T pop() throws EmptyException {
while (true) {
Node returnNode = tryPop();
if (returnNode != null)
return returnNode.value;
else
backoff.backoff();
}
}

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

Give the code for the tryPop

A

protected Node tryPop() throws EmptyException {
Node oldTop = top.get();
if (oldTop == null)
throw new EmptyException()
Node newTop = oldTop.next;
if (top.compareAndSet(oldTop, newTop))
return oldTop;
else
return null;
}

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

What is good/bad about the lock-free stack

A

Good: No locking
Bad: Even with backoff there is huge contention at the top. no real parallelism

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

Does the lock-free stack scale properly? And why?

A

No.
Stack’s top field is a source of contention
Sequential bottleneck ( Method calls can proceed only one after the other)

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

Does exponential backoff help for the lock free stack?

A

No. Makes contention better but does nothing for bottleneck

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