1
我是Deuce STM的新手,想知道如何去執行使用Deuce STM的隊列。這是我目前的工作實現 -Queue Using Deuce STM
Node類包含兩個字段 - 值和指向下一個字段的指針。
public class STMQueue {
Node head, tail;
public STMQueue() {
Node sentinel = new Node(-1);
tail = sentinel;
head = sentinel;
}
@Atomic
public void enq(int x) {
Node node = new Node(x);
tail.next = node;
tail = node;
}
@Atomic
public int deq() throws EmptyException{
Node node = head.next;
if(node == null) {
throw new EmptyException();
}
int retVal = node.value;
head = node;
return retVal;
}
}
這是實施它的正確方法嗎?我們是否必須手動拋出一個事務異常?如果這是正確的,那麼我們如何衡量已終止的交易數量 或重試?