/// <summary> /// Adds the given input and runs the computer until an output occurs. /// Returns the first output or null, if the comuter halts. /// </summary> public long?RunWith(long input) { Inputs.Enqueue(input); while (CurrentOpcode != OpCode.Halt) { ExecuteStep(); if (CurrentOpcode == OpCode.SaveOutput) { return(Outputs.Dequeue()); } } return(null); }
public long?GetNextOutput() { var nextOutput = default(long?); while (!nextOutput.HasValue) { if (OutputReady) { lock (OutputLock) { if (Outputs.Count > 0) { return(Outputs.Dequeue()); } } } Thread.Sleep(1); if (!OutputReady && (Exited || Paused)) { break; } } return(null); }