multithreading - How to interrupt ReadLn from another thread -
in free-pascal i'm going create cross platform console program of it's work in bunch of threads (tthread).
the main program used recieving few user commands , , executing these (and keep whole program running).
this loop program's main loop works on both windows , linux no cpu usage:
repeat write('> '); readln(s); // execute command until s='exit';
but need threads command main program work. means need way stop readln thread go on , check command flag. if somehow send enter-keypress trick readln end fine.
are there other ways make cross platform main loop listens user string or key presses , @ same time commandable other threads?
yes, use unit keyboard. abstracted keyboard support allows peek events (keys) , , means boolean set in thread make exit loop.
see keyboard unit in (rtl) manual , textconsole games (fpctris, samegame) come standard fpc install.
Comments
Post a Comment