/// <summary> /// Method that executes single cycle of entire machine /// 1. All processors read data /// 2. All processors execute computations /// 3. All processors write their results /// </summary> /// <returns>Returns true if there are any working processors and false if all of them are stopped</returns> private bool Tick() { memory.ClearRequests(); int workingProcessorsCount; List <RWRequest> readRequests = GetReadRequests(); List <RWRequest> writeRequests = new List <RWRequest>(); //Step 1. We post read requests to memory state = PRAMState.Reading; this.memory.PostReadRequests(readRequests); //Step 2. Now all processors are called with data they have read or null if they havent posted any new reqeuests state = PRAMState.Processing; workingProcessorsCount = this.RunProcessors(readRequests); //Step 3. We now collect all write requests from processors state = PRAMState.Writing; writeRequests = this.GetWriteRequests(); //Step 4. And post them to memory memory.PostWriteRequests(writeRequests); //Step 5. Now we write data to memory foreach (RWRequest request in writeRequests) { memory.WriteData(request); } tickCount++; if (workingProcessorsCount > 0) { return(true); } this.isStopped = true; return(false); }