問題は次のとおりです。各スレッドで順番に使用する必要がある5つのメソッドを言いました
Method1(); 次に Method2(); 次に Method3(); 次に Method4(); 次に Method5();
1から5までの番号が付けられた5つのスレッドも実行しています
次のシナリオを実装したいと思います。
スレッド 1 で method1 の使用を開始してから、method2 に移動する [並行して、現在使用されていない method1 の使用をスレッド 2 で開始する]
次に、スレッド 1 がメソッド 3 に移動し、スレッド 2 がメソッド 2 に進むと、スレッド 3 は解放されたメソッド 1 の使用を開始する必要があります。
public void Execute(object OPCounter)
{
//Method 1
lock (thisLock)
{
FetchedInstructionQueue[PCounter] = Stager.Stage1(InstructionsMemory);
}
//Method 2
lock (thisLock)
{
DecordedInstructionQueue[PCounter] = Stager.Stage2(FetchedInstructionQueue, regMem);
}
//Method 3
lock (thisLock)
{
ALUResultQueue[PCounter] = Stager.Stage3(DecordedInstructionQueue);
}
lock (thisLock)
{
MemoryQueue[PCounter] = Stager.Stage4(DecordedInstructionQueue, memory, ALUResultQueue);
}
lock (thisLock)
{
object obj = Stager.Stage5(DecordedInstructionQueue, ALUResultQueue, regMem, memory, MemoryQueue);
InternalWriter(PCounter, obj);
}
}
///This is the initiator of threads
private void ExecuteBtn_Click(object sender, EventArgs e)
{
InstructionsMemory = InstructionsTextBox.Text.Split('\n');
FetchedInstructionQueue = new string[InstructionsMemory.Length];
DecordedInstructionQueue = new Instruction[InstructionsMemory.Length];
ALUResultQueue = new int[InstructionsMemory.Length];
MemoryQueue = new int[InstructionsMemory.Length];
Thread[] threads = new Thread[InstructionsMemory.Length];
for (APCounter = 0; APCounter < InstructionsMemory.Length; APCounter = 5 + APCounter)
{
if (APCounter + 5 < InstructionsMemory.Length)
{
object s1 = APCounter;
object s2 = APCounter + 1;
object s3 = APCounter + 2;
object s4 = APCounter + 3;
object s5 = APCounter + 4;
threads[APCounter] = new Thread(new ParameterizedThreadStart(Execute));
threads[APCounter + 1] = new Thread(new ParameterizedThreadStart(Execute));
threads[APCounter + 2] = new Thread(new ParameterizedThreadStart(Execute));
threads[APCounter + 3] = new Thread(new ParameterizedThreadStart(Execute));
threads[APCounter + 4] = new Thread(new ParameterizedThreadStart(Execute));
threads[APCounter].Start(s1);
threads[APCounter + 1].Start(s2);
threads[APCounter + 2].Start(s3);
threads[APCounter + 3].Start(s4);
threads[APCounter + 4].Start(s5);
}
}