title: read value from input design for both console and gui app (c++)
body: <p>I've got a c++ library with a class that implements a virtual machine (called 'VM') of a custom programming language. This language have some different instructions that can be executed, among which there is "read value from input" instruction. The VM can be run in two modes: execute single instructions step by step (until machine is done) or execute all instructions at once. It can be also used in two applications: console and a GUI application.</p>
  
  <p>Until now I had only a console application. When the "read value from input" instruction was executed, it just used std::cin to read the value, so the virtual machine stopped until the input was submitted. The problem occurs when I'm trying to create a GUI for the VM. I'll use a typical text input instead of <code>std::cin</code>.</p>
  
  <p>The question is: <strong>what do you think is the best way to model such problem</strong> from the point of executing instructions? How should the VM behave when the "read value from input" instruction is executed? Before a user click "execute single instruction" he doesn't know what kind of instruction is it going to be, so he can't submit the input before the instruction is executed.</p>
  
  <p>I was thinking about adding a new state property to the VM: <code>{working|awaiting_input}</code>. During the "read" instruction runtime the machine should suspend until it gets the input. And when the GUI layer fetches the input from the user, it'd call VM's <code>passInput(inputValue)</code> new method which additionally wakes VM up (to either finish the single instruction or all of them). Can you think of an easier solution (e.g. without adding a state property)?</p>