in reply to Re^11: Forking Clients
in thread Forking Clients

As a followup, I have a separate issue that I think could be solved via threads as well.

In certain instances, a system call might be made which in turn requires some user input, this system call will essentially hang there until the underlying process waiting for the response is killed. What I was hoping of doing was to create an asynchronous thread and have it run the command, I would loop for some set amount of time checking to see if the thread is joinable, if it is then great, if it times out then exit or kill the thread.

I can't do the timeout in the function itself since there will be no response to the system call, that is why I am attempting to do it via thread that I can kill. The issue I am seeing is that after I launch the thread, anytime I attempt to do anything with the thread, i.e. to get information on it, it hangs.

Any ideas? Thanks

my $queue1 = new Thread::Queue; #Thread Timeout Test my $command = 'diskpart'; #my ($thr) = threads->create(sub {return `$command`;}); my ($thr) = async{ my @resp1 :shared = `$command`; $queue1->enqueue(\@resp1, undef); return; }; threads->list(); my $count = 60 * 1; #wait a min (testing) while ($count and !$thr->is_joinable()) { sleep(1); count--; } if (!$thr->is_joinable()) { threads->exit(); } ...

The threads->list() call hangs (so does any other thread related call. If I do $command = 'dir'; everything works as expected since it is not stuck waiting for user input.

Replies are listed 'Best First'.
Re^13: Forking Clients
by BrowserUk (Patriarch) on Oct 21, 2008 at 18:48 UTC