2014-04-26 39 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對象...