Java 使用Deuce STM排队
我是Deuce STM的新手,想知道如何使用Deuce STM实现队列。以下是我目前的工作执行情况- Node类包含两个字段—值和指向下一个字段的指针Java 使用Deuce STM排队,java,multithreading,transactions,atomic,stm,Java,Multithreading,Transactions,Atomic,Stm,我是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)
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;
}
}
这是正确的实施方式吗?我们必须手动抛出事务异常吗?如果这是正确的,那么我们如何衡量中止的事务数
还是重试?我从未与DeuceSTM合作过。话虽如此,有几点值得注意: 看来你的空头支票是错的;根据构造函数,如果node==sentinel,则应为。 从盖伊·科兰(Guy Korland)那里,我相信统计数据并没有得到实施;您必须修改上下文对象,看起来。。。