In Free-Pascal I'm going to create a cross platform console program which will do most of it's work in a bunch of threads (TThread).
The main program is only used for recieving a few user commands now and then and executing these (and to keep the whole program running).
This loop as the program's main loop works perfectly on both Windows and Linux with no cpu usage:
repeat
Write('> ');
ReadLn(s);
// execute command
until s='exit';
But I need the threads to command the main program to do some work. This means I need a way to stop the ReadLn from another thread to go on and check for a command flag. If I could somehow send an Enter-keypress to trick ReadLn to end it would be fine.
Are there other ways to make a cross platform main loop which listens for a user string or key presses and at the same time will be commandable from other threads?