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