Dual data stractures Flashcards

1
Q

Idea of Dual data structures

A

reduce synchronization overhead of the synchronous queue. split enq and deq into 2 steps

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

How does the deq work?

A

if try to remove from empty queue:
put reservation object in queue. wait for enq. Spin on flag in reservation

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

how does enq work?

A

if sees reservation:
Fulfill by depositing item. set flag to notify dequer

can also enq its own reservations and spin on flag waiting for deq

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

What does the queue consist of(what is the queue made up of)?

A

either enq reservation, deq reservations or is empty

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

What is good about dual data structures

A

waiting threads spin on locally cached flag. is linearizable. Ensures fairness

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

how do the nodes of the dual data structure look?

A

private enum NodeType {ITEM, RESERVATION};
private class Node {
volatile NodeType type;
volatile AtomicReference<T> item;
volatile AtomicReference<Node> next;
Node (T myItem, NodeType myType) {
item = new AtomicReference<T> (myItem);
next = new AtomicReference<Node>(null);
type = myType;
}
}</Node></T></Node></T>

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

how does the enq code look like?

A

public void enq(T e) {
Node offer = new Node (e, ITEM);
while (true) {
Node t = tail.get(), h = head.get();
if (h == t || t.type == ITEM) {
Node n = t.next.get();
if (t == tail.get()) {
if (n != null) {
tail.compareAndSet(t, n);
} else if (t.next.CAS(n, offer)) {
tail.compareAndSet(t, offer);
while (offer.item.get() == e) {}
h = head.get();
if (offer == h.next.get())
head.compareAndSet(h, offer);
return; }}
} else {
Node n = h.next.get();
if (t != tail.get() || h != head.get() || n ==
null) {
continue;
}
boolean success = n.item.compareAndSet(null,e);
head.compareAndSet(h, n);
if (success)
return;
}}}

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