我是 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;
}
}
这是正确的实现方法吗?我们必须手动抛出事务异常吗?如果这是正确的,那么我们如何衡量中止的交易数量 或者重试?
最佳答案
我从未与 DeuceSTM 合作过。话虽如此,有几点需要注意:
- 看来您的空支票是错误的;应该是
if (node == sentinel)
基于您的构造函数。 - This message盖伊·科兰 (Guy Korland) 的观点让我相信统计数据并未得到落实;您似乎必须修改 Context 对象...
关于java - 使用 Deuce STM 进行队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23310295/