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.
my $clone = $obj->shared_clone($deep_variable);
$obj->coordinate_threads is false, this will simply return the
lock($var) if $obj->coordinate_threads;
Use the normal Perl lock() function if and only if
<$obj-coordinate_threads>> is true.
Unfortunately, we cannot provide a lock() method to do this for you. The scope of the lock is lock()'s lexical.