[tpm] Control-D blocks STDIN when another thread is running

Tom Legrady legrady at gmail.com
Mon May 13 15:41:12 PDT 2013


When you press ^D, whether before or after the thread has printed "done",
the main process exits the loop, and goes on to the join. If necessary, it
waits for the thread to terminate and the join() to be performed.

How would you like it to be different? I suppose you could detect a special
input, and exit at that point.


On Mon, May 13, 2013 at 4:39 PM, Viktor Pavlenko <vvp at cogeco.ca> wrote:

> Hello All!
>
> I have a multithreaded perl script where the main thread runs an
> interactive loop getting user input and passes it for processing to
> another thread. All works fine except when I press Control-D at the
> prompt. There's no response and I have to use ^\ to kill the script.
>
> The problem can be reproduced with the following script:
>
> bash-3.2$ cat ./stdin_test.pl
> #!/usr/bin/perl -w
>
> use strict;
> use threads;
>
> my $t = threads->create(sub { sleep 10; print "done\n" });
>
> while (<>) {
>       print $_;
> }
>
> $t->join();
> print "bye\n";
>
> bash-3.2$ ./stdin_test.pl
> aa
> aa
> <------------- hitting ^d here, blocks until another thread exits
> done
> bye
> bash-3.2$
>
> I'm on linux, tried both perl versions 5.8.8 and 5.10.1. Google search
> strangely gave me nothing.
>
> --
> Viktor
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130513/5c6ef441/attachment.html>


More information about the toronto-pm mailing list