title: Multithreaded console I/O
body: <p>I'm using a console in my multithreaded application.  Right now, it only accepts output (printf and the like) and so far I have no issues.  However, I want to be able to support console input as well, and this is where my life gets complicated.</p>
  
  <p>To forewarn, I'm very unfamiliar with the more complicated nuances of working with console input and output.  My experience in the subject doesn't go much further than printf/cout, scanf/cin, and using <code>SetConsoleTextAttribute()</code> to change the color (on windows).</p>
  
  <p>I would prefer to keep my program as cross-compatible as possible, but I'm not opposed to having to write platform-specific code, as long as I can find viable alternatives for other platforms.</p>
  
  <p>Conceptually, I'd like the console to run on it's own thread, so that it can lock up while waiting with cin without freezing the whole program or one of the other threads.  Any thread could send console output to this thread which would output it in a clean manner (probably using a thread-safe queue), and any input that the console reads would send the command off to the appropriate thread.</p>
  
  <p>My first problem is that while I'm typing some input, any output will show up in the middle of what I'm typing.  The solution I would like to handle this would be to reserve the bottom line of the console for input, and have output go to the second last line, pushing the input line down.  How can I do this?</p>