Thread to watch keyboard during main's infinite loop
Daren Scot Wilson
darenw at darenscotwilson.com
Thu May 7 01:33:12 UTC 2020
On Thursday, 7 May 2020 at 01:02:57 UTC, ag0aep6g wrote:
Thank you, this is 110% helpful.
Actually, I'd like to return the excess 10%. My dmd compiler
does not like:
import core.thread: sleep;
so I put the code back the way I had, just to get on with work.
> Use `shared` so that all threads use the same variables:
>
> shared bool running=true;
> shared char command = '?';
>
"shared" did the job. I had read about "thread local" and
"shared" in D before, but did not comprehend. Now I do :)
> This sequence of events is entirely possible:
>
> 1) main: cmd = command
> 2) cmdwatcher: command = c
> 3) main: command = ' '
>
> It won't happen often, but if it does, your input has no effect.
For this tool, lost key hits are not a problem. At least, that's
what I say for now. I may be back next week for help with that.
For now, the trousered ape running the software will just have to
tap the key again. (Or the key + Enter.)
More information about the Digitalmars-d-learn
mailing list