Docsity

Trace 1 for Programming Language Technology - Lecture Slides | CMSC 433, Study notes of Programming Languages

Toggle sidebar
bg1
Trace 1
public boolean put(E item) {
1 Node<E> newNode = new Node<E>(item, null);
2 while (true) {
3 Node<E> curTail = tail.get();
4 Node<E> tailNext = curTail.next.get();
5 if (curTail == tail.get()) {// did tail change?
6 if (tailNext != null) { // Queue in int. state, advance tail
7 tail.compareAndSet(curTail, tailNext);
8 else { // In quiescent state, try inserting new node
9 if (curTail.next.compareAndSet(null, newNode)) {
// Insertion succeeded, try advancing tail
10 tail.compareAndSet(curTail, newNode);
// will fail if tail already moved
11 return true;
}
}
}
}
}
Var
T1
T2
tailNext
curTail
newNode
head
tail
0 λ
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Trace 1 for Programming Language Technology - Lecture Slides | CMSC 433 and more Study notes Programming Languages in PDF only on Docsity!

Trace 1

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext

curTail

newNode

head

tail

Trace 1

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext

curTail

newNode

head

tail

Trace 1

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ λ

curTail

newNode

head

tail

Trace 1

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ λ

curTail

newNode

head

tail

Trace 1: T1 wins

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ λ

curTail

newNode

head

tail

Trace 1: After CAS

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ λ

curTail

newNode

head

tail

Trace 1: T1 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ λ

curTail

newNode

head

tail

Trace 1: After CAS

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ λ

curTail

newNode

head

tail

Trace 1: T2 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ

curTail

newNode

head

tail

Trace 1: T2 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ

curTail

newNode

head

tail

Trace 1: T2 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ

curTail

newNode

head

tail

Trace 1: T2 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ

curTail

newNode

head

tail

Trace 1: T2 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ

curTail

newNode

head

tail

Trace 1: T2 Continues

public boolean put(E item) { 1 Node newNode = new Node(item, null); 2 while (true) { 3 Node curTail = tail.get(); 4 Node tailNext = curTail.next.get(); 5 if (curTail == tail.get()) {// did tail change? 6 if (tailNext != null) { // Queue in int. state, advance tail 7 tail.compareAndSet(curTail, tailNext); 8 else { // In quiescent state, try inserting new node 9 if (curTail.next.compareAndSet(null, newNode)) { // Insertion succeeded, try advancing tail 10 tail.compareAndSet(curTail, newNode); // will fail if tail already moved 11 return true; } } } }

Var T1 T

tailNext λ

curTail

newNode

head

tail