2014-04-26 40 views
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; 
} 

} 

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

回答

0

我从来没有与DeuceSTM合作过。说了这么几句话:

  • 看来你的空检查是错误的;基于你的构造函数应该是if (node == sentinel)。来自Guy Korland的
  • This message使我相信统计数据没有实现;您将不得不修改Context对象...