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;
}
}
这是实施它的正确方法吗?我们是否必须手动抛出一个事务异常?如果这是正确的,那么我们如何衡量已终止的交易数量 或重试?