1

我是 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;
}

}

这是实现它的正确方法吗?我们是否必须手动抛出事务异常?如果这是正确的,那么我们如何衡量被中止或重试的事务数?

4

1 回答 1

0

我从未使用过 DeuceSTM。话虽如此,有几点注意事项:

  • 看来您的空支票是错误的;应该if (node == sentinel)基于你的构造函数。
  • Guy Korland 的这条信息让我相信没有实施统计数据;你将不得不修改它看起来的 Context 对象......
于 2014-04-30T00:55:18.630 回答