strat has asked for the wisdom of the Perl Monks concerning the following question:
I just installed Activestate Perl 5.8 Beta Built 802 under Win2k and played around a bit with threads. Due to the good tutorial at YAPC::Europe everything worked fine...
Then I got a bad idea; i remembered an old DOS program which waited for an input for n seconds, and if it didn't come within those n seconds, it continued with a standard value. I forgot its name, but maybe you know it. Well, might be possible doing so by using threads, I thought...
Here are some lines of code:
Well, my problem is how to get rid off the blocked thread if the user doesn't enter anything... If I run $inputThread->join, the program will block forever. If I run $inputThread->detach() (or do nothing), I will at least be able to continue with my main program, but have got a blocked thread somewhere, and if a user enters anything later, it might give strange results because the shared Variable $Input suddenly has got another value.#! /usr/bin/perl use 5.008; use strict; use warnings; use threads; use threads::shared; our $Input : shared = ""; sub getInput { print "Please enter some- or nothing: "; my $input = <STDIN>; chomp($input); $Input = $input if defined $input; # or whatever... } my $oldInput = $Input; my $inputThread = threads->create('getInput'); sleep 5; unless ($Input eq $oldInput) { $inputThread->join(); print "Input was: $Input\n"; sleep 2; } else { print "Continuing with 'abcd' as a standard value...\n"; # WHAT CAN I DO HERE ? }
Do you know how to solve this problem? (It is not a production problem, but I'm very interested if and how this can be done with threads; well, with fork it wouldn't be a big problem...)
Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "killing" perl5.8-threads
by strider corinth (Friar) on Nov 13, 2002 at 21:05 UTC | |
|
Re: "killing" perl5.8-threads
by waswas-fng (Curate) on Nov 13, 2002 at 17:43 UTC | |
by waswas-fng (Curate) on Nov 13, 2002 at 21:26 UTC | |
|
Re: "killing" perl5.8-threads
by nothingmuch (Priest) on Nov 13, 2002 at 19:28 UTC |