コンセンサスに任意の数のスレッドが到達できることを示すために、peek() メソッドを使用するキューを使用するコンセンサス プロトコルを実装する必要があります。つまり、peek() メソッドを使用するキューには無限のコンセンサス数があります。
これは私のコードです
import java.util.LinkedList;
import java.util.Queue;
public class PeekConsensus extends ConsensusProtocol<Integer>
{
Queue<Integer> queue ;
public PeekConsensus(int threadCount)
{
super(threadCount); //threadCount is a command line argument from the main class specifying the number of threads to handle this process
queue = new LinkedList<Integer>() //FIFO queue
}
public Integer decide(Integer value)
{
this.propose(value); // stores "value" in a vector named proposed, at index ThreadID.get()
int i = ThreadID.get() ;
queue.add(i)
System.out.println("Thread " + i + " : " + i) ; // Required by specifications to print thread id and the value added when an item is enqueued
System.out.println("Thread " + i + " : " + queue.peek()) ; // Required by specifications to print thread id and the value of peek() when when peek() is called
return proposed.elementAt(queue.peek()) ;
}
}
私の理解では、2 つのスレッドが異なる値を返す場合、peek() は異なるスレッド ID を返す必要があり、スレッド ID をプッシュする前に各スレッドが独自の値をプロポーザルに書き込むため、妥当性が保証されるため、これは機能するはずです。
私がどこで間違っているのかを理解し、コードを修正する方法を教えてくれる人はいますか