Using threads for control input (keyboard, serial)
I have a version of my app that is using threads to wait for keyboard input and input from the serial port (one thread for each). Based on what input is gathered from these threads, they set a variable in the calling thread so it knows what to do. Both threads are set up to loop infinitely and wait for keystrokes (thread1) or data coming in from the serial port (thread2).
The value they set in the calling thread's variable determines its course of action. The calling thread itself is in a loop (constantly reading this variable).
This seems to be working okay so far, but is there a better way to do this? I suppose I could put the checks for key and serial port input in the main loop, but what advantage would that offer? As I mentioned, the main loop just constantly checks a variable, so what does it matter whether it's set by its own loop or by some other thread?