in reply to Re: Create a separate process with a sub...
in thread Create a separate process with a sub...
# One (of several) things missing from the API as it stands # is any way to determine if the thread has finished # without blocking.
I think that's pretty easy to do with Thread::Exit.
Hmmm... maybe I should just add that to Thread::Exit... ;-)use threads (); use threads::shared (); my %exited : shared; use Thread::Exit end => sub { $exited{threads->tid} = 1 }; my $thread = threads->new( sub { whatever } ); my $tid = $thread->tid; while (!$exited{$tid}) { # do your stuff }
Liz
Update:
I worked a little on it ;-)
The uploaded file
Thread-Running-0.01.tar.gz
has entered CPAN as
file: $CPAN/authors/id/E/EL/ELIZABETH/Thread-Running-0.01.tar.gz
size: 3963 bytes
md5: 847d0175b6f5f355c97d20c73dce7311
The POD starts with:
NAME
Thread::Running - provide non-blocking check whether threads are running
SYNOPSIS
use Thread::Running; # exports running(), exited() and tojoin()
use Thread::Running qw(running); # only exports running()
use Thread::Running (); # threads class methods only
my $thread = threads->new( sub { whatever } );
while (threads->running( $thread )) {
# do your stuff
}
$_->join foreach threads->tojoin;
until (threads->exited( $tid )) {
# do your stuff
}
DESCRIPTION
This module adds three features to threads that are sorely
missed by some: you can check whether a thread is running,
whether it can be joined or whether it has exited without
waiting for that thread to be finished (non-blocking).
For the impatient: it can also be fetched from my own list of CPAN modules.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Create a separate process with a sub...
by BrowserUk (Patriarch) on Aug 15, 2003 at 12:14 UTC | |
by liz (Monsignor) on Aug 15, 2003 at 12:43 UTC | |
by BrowserUk (Patriarch) on Aug 15, 2003 at 13:36 UTC |