S
Samuel
Given the following snippet:
-----------------------
#!/usr/bin/env perl
use threads;
sub threadfunc { my $i = 0; while ($i < 3) { shift; print; $| = 1; $i+
+; sleep(1); } }
my $thread1 = threads->create(\&threadfunc, '.');
my $thread2 = threads->create(\&threadfunc, '#');
print "Threads created.\n";
while (threads->list() > 0) {
for my $thread (threads->list()) {
next unless $thread->running(); # how can this be done?
print "Joining thread: $thread (" . $thread->tid() . ")\n";
$thread->join();
}
print "Waiting...\n";
sleep 1;
}
print "Done.\n";
-----------------------
How can I check whether a thread is still running? Note the comment in
the code at "next unless $thread->running();".
I realize that this is not necessary in this situation, but this is
only a test case. Any hints?
-Samuel
-----------------------
#!/usr/bin/env perl
use threads;
sub threadfunc { my $i = 0; while ($i < 3) { shift; print; $| = 1; $i+
+; sleep(1); } }
my $thread1 = threads->create(\&threadfunc, '.');
my $thread2 = threads->create(\&threadfunc, '#');
print "Threads created.\n";
while (threads->list() > 0) {
for my $thread (threads->list()) {
next unless $thread->running(); # how can this be done?
print "Joining thread: $thread (" . $thread->tid() . ")\n";
$thread->join();
}
print "Waiting...\n";
sleep 1;
}
print "Done.\n";
-----------------------
How can I check whether a thread is still running? Note the comment in
the code at "next unless $thread->running();".
I realize that this is not necessary in this situation, but this is
only a test case. Any hints?
-Samuel