Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]8014[/thread]

Gibt es für threads Methode done()?

Leser: 1


<< >> 3 Einträge, 1 Seite
Gast Gast
 2006-05-23 15:47
#66541 #66541
Hallo!

Es gibt doch für ithreads (Modul: 'Thread' ) die Methode done(), mit der man testen kann, ob ein Thread am ende angelangt ist oder nicht.
Nun würde ich so eine Methode für das Modul 'threads' benötigen. Gibt es dafür eine Möglichkeit zu testen: "Wenn thread am Ende, mache...."? Finde dazu keine Information. Kann mit bitte jemand helfen?

MfG
Maria
GwenDragon
 2006-05-23 22:05
#66542 #66542
User since
2005-01-17
14548 Artikel
Admin1
[Homepage]
user image
Es gibt leider keine solche Methode im Modul threads.

Ich weiß nicht, ob das dir hilft:
http://www.mathematik.uni-ulm.de/help/perl5/doc/perlthrtut.html
Quote
What Threads Are Running?

threads->list returns a list of thread objects, one for each thread that's currently running and not detached. Handy for a number of things, including cleaning up at the end of your program:
# Loop through all the threads
foreach $thr (threads->list) {
# Don't join the main thread or ourselves
if ($thr->tid && !threads::equal($thr, threads->self)) {
$thr->join;
}
}

If some threads have not finished running when the main Perl thread ends, Perl will warn you about it and die, since it is impossible for Perl to clean up itself while other threads are running
\n\n

<!--EDIT|GwenDragon|1148407932-->
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

murphy
 2006-05-23 22:40
#66543 #66543
User since
2004-07-19
1776 Artikel
HausmeisterIn
[Homepage]
user image
Eine Überprüfung der Liste von Threads klingt nach einer ganz guten Idee.

Ansonsten könnte man sich noch mittels gemeinsamer Variablen eine Benachrichtigung für das Ende eines Threads bauen, also etwa so:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use strict;
use warnings;

use threads;
use threads::shared;

my $done = 0;
share $done;

async {
sleep 10; # tue hier stattdessen etwas sinnvolles
lock $done;
$done = 1;
cond_broadcast $done;
};

sub is_done {
lock $done;
cond_timedwait $done, time;
return $done;
}

while (!is_done) {
print "Laeuft noch...\n";
sleep 1;
}
When C++ is your hammer, every problem looks like your thumb.
<< >> 3 Einträge, 1 Seite



View all threads created 2006-05-23 15:47.