TB2::CanThread - A role for an object which must be aware of threading
package MyThing; use TB2::Mouse; with 'TB2::CanThread'; # Don't coordinate with other threads my $uncoordinated = MyThing->new( coordinate_threads => 0 ); # Coordinate with other threads by default my $coordinated = MyThing->new; # If coordinate_threads are on and threads are loaded, these will # do their thing. Otherwise they are no-ops. $object = $coordinated->shared_clone($object); $coordianted->lock($thing); $coordianted->share(\@array);
This role manages the sharing of objects between threads.
If true, this TestState will coordinate its events across threads.
If false, events in child threads will not be seen by other threads. Each thread will have a detached state.
Default is true, to coordinate.
This cannot be changed once the TestState has been constructed.
These all work like their threads::shared counterparts if and only if $obj->coordinate_threads is true. Otherwise they are no-ops.
$obj->coordinate_threads
$obj->share(\$simple_variable);
my $clone = $obj->shared_clone($deep_variable);
If $obj->coordinate_threads is false, this will simply return the $variable.
$variable
lock($var) if $obj->coordinate_threads;
Use the normal Perl lock() function if and only if <$obj-coordinate_threads>> is true.
<$obj-
Unfortunately, we cannot provide a lock() method to do this for you. The scope of the lock is lock()'s lexical.
threads::shared
To install Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Simple
CPAN shell
perl -MCPAN -e shell install Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.