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

Viktor Pavlenko vvp at cogeco.ca
Mon May 13 18:03:13 PDT 2013


You are right Tom, I wasn't seeing obvious. For some reason I believed
it hanged in (<>). My bad, thanks for pointing it out.

-- 
Viktor

>>>>> "TL" == Tom Legrady <legrady at gmail.com> writes:

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

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


    TL> 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


More information about the toronto-pm mailing list