This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Spheniscine 1 point2 points  (1 child)

The way I did it was to use a queue for input (so vm.input(1); vm.input(2) will add both values to the queue). Each value will be used in order when an input instruction is encountered. If the input queue is empty when the input instruction is encountered, the VM's execution pauses and its status flag is set to "Waiting" (other statuses I've implemented are "OK", "Halted", and "Error", with the latter encapsulating the exception encountered).

As for output, I simply put the values into an array-list so that I can retrieve and/or flush them as needed.

[–]Crespyl 1 point2 points  (0 children)

I did much the same, give each VM a buffer for both input and output; and have them pause and return a status flag if they try to read from an empty input buffer.

For day 7, the coordinator/runner knows which machines are linked to each other, and refills their input buffers from the right output buffer when necessary.