Thread::Isolate - Create Threads that can be called externally and use them to isolate modules from the main thread.
This module has the main purpose to isolate loaded modules from the main thread.
The idea is to create the Thread::Isolate object and call methods, evaluate codes and use modules inside it, with synchronized and unsynchronized calls.
Synchronized calls:
use Thread::Isolate ; my $thi = Thread::Isolate->new() ; $thi->eval(' 2**10 ') ; ... $thi->eval(q` sub TEST { my ( $var ) = @_ ; return $var ** 10 ; } `) ; print $thi->call('TEST' , 2) ; ... $thi->use('Data::Dumper') ; print $thi->call('Data::Dumper::Dumper' , [123 , 456 , 789]) ;
Here's an example of an unsynchronized call (detached):
my $job = $thi->eval_detached(q` for(1..5) { print "in> $_\n" ; sleep(1); } return 2**3 ; `); $job->wait_to_start ; while( $job->is_running ) { print "." ; } print $job->returned ;
Create a new Thread::Isolate object.
call 'use MODULE qw(ARGS)' inside the thread,
Evaluate a CODE and paste ARGS inside the thread.
Evaluate detached (unsynchronous) a CODE and paste ARGS inside the thread.
Returns a Thread::Isolate::Job object.
call FUNCTION inside the thread.
call detached (unsynchronous) FUNCTION inside the thread.
Shutdown the thread.
Return TRUE if the thread exists.
Return TRUE if the thread is running some job.
When a deteched method is called a job is returned. Here are the methods to use the job object:
Return TRUE if the job was started.
Return TRUE if the job is running.
Return TRUE if the job was finished.
Wait until the job starts. (Ensure that the job was started).
Wait until the job is finished. (Ensure that the job was fully executed).
Returns the arguments returneds by the job.
Same as wait().
Returns the arguments returneds by the job. It will wait the job to finish too.
Thread::Tie::Thread, threads::shared.
Safe::World.
Graciliano M. P. <gmpassos@cpan.org>
I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P
This module was inspirated on Thread::Tie::Thread by Elizabeth Mattijsen, <liz at dijkmat.nl>, the mistress of threads. ;-P
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Thread::Isolate::EVAL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Thread::Isolate::EVAL
CPAN shell
perl -MCPAN -e shell install Thread::Isolate::EVAL
For more information on module installation, please visit the detailed CPAN module installation guide.