我是 Deuce STM 的新手,想知道如何使用 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;
}
}
这是实现它的正确方法吗?我们是否必须手动抛出事务异常?如果这是正确的,那么我们如何衡量被中止或重试的事务数?