Cancelling a stdin.read?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 11 07:53:31 PDT 2016
On Sunday, 10 April 2016 at 08:29:22 UTC, Lass Safin wrote:
> Thus, my question is: Is there any way to cancel the read from
> stdin prematurely from another thread, so that the thread can
> finish?
What operating system are you on?
I wouldn't be using threads for this at all, you might want to
reorganize the program to get terminal events sent to the same
gui event loop so exiting it would exit all of it.
But failing that, canceling an I/O request can be done by sending
yourself a signal on posix and on Windows there's a system API
call that one thread can cancel another thread's blocking read.
The D library would see these cancels as an error and throw an
exception. You could catch it or let it kill the thread, since
you want to exit anyway.
More information about the Digitalmars-d-learn
mailing list