disabled
 Q     populate such variables B<after> declaring them as shared.  (Scalar
and scalar refs are not affected by this problem.)

Blessing a shared item after it has been nested in another shared item does
not propagate the blessing to the shared reference:

  my $foo = &share({});
  my $bar = &share({});
  $bar->{foo} = $foo;
  bless($foo, 'baz');   # $foo is now of class 'baz',
                        # but $bar->{foo} is unblessed.

Therefore, you should bless objects before sharing them.

It is often not wise to share an object unless the class itself has been
written to support sharing.  For example, a shared object's destructor may
get called multiple times, once for each thread's scope exit, or may not
get called at all if it is embedded inside another shared object.  Another
issue is that the contents of hash-based objects will be lost due to the
above mentioned limitation.  See F<examples/class.pl> (in the CPAN
distribution of this module) for how to create a class that supports object
sharing.

Destructors may not be called on objects if those objects still exist at
global destruction time.  If the destructors must be called, make sure
there are no circular references and that nothing is referencing the
objects before the program ends.

Does not support C<splice> on arrays.  Does not support explicitly changing
array lengths via $#array -- use C<push> and C<pop> instead.

Taking references to the elements of shared arrays and hashes does not
autovivify the elements, and neither does slicing a shared array/hash over
non-existent indices/keys autovivify the elements.

C<share()> allows you to C<< share($hashref->{key}) >> and
C<< share($arrayref->[idx]) >> without giving any error message.  But the
C<< $hashref->{key} >> or C<< $arrayref->[idx] >> is B<not> shared, causing
the error "lock can only be used on shared values" to occur when you attempt
to C<< lock($hashref->{key}) >> or C<< lock($arrayref->[idx]) >> in another
thread.

Using C<refaddr()> is unreliable for testing
whether or not two shared references are equivalent (e.g., when testing for
circular references).  Use L<is_shared()|/"is_shared VARIABLE">, instead:

    use threads;
    use threads::shared;
    use Scalar::Util qw(refaddr);

    # If ref is shared, use threads::shared's internal ID.
    # Otherwise, use refaddr().
    my $addr1 = is_shared($ref1) || refaddr($ref1);
    my $addr2 = is_shared($ref2) || refaddr($ref2);

    if ($addr1 == $addr2) {
        # The refs are equivalent
    }

L<each()|perlfunc/"each HASH"> does not work properly on shared references
embedded in shared structures.  For example:

    my %foo :shared;
    $foo{'bar'} = shared_clone({'a'=>'x', 'b'=>'y', 'c'=>'z'});

    while (my ($key, $val) = each(%{$foo{'bar'}})) {
        ...
    }

Either of the following will work instead:

    my $ref = $foo{'bar'};
    while (my ($key, $val) = each(%{$ref})) {
        ...
    }

    foreach my $key (keys(%{$foo{'bar'}})) {
        my $val = $foo{'bar'}{$key};
        ...
    }

This module supports dual-valued variables created using C<dualvar()> from
L<Scalar::Util>.  However, while C<$!> acts
like a dualvar, it is implemented as a tied SV.  To propagate its value, use
the follow construct, if needed:

    my $errno :shared = dualvar($!,$!);

View existing bug reports at, and submit any new bugs, problems, patches, etc.
to: L<http://rt.cpan.org/Public/Dist/Display.html?Name=threads-shared>

=head1 SEE ALSO

threads::shared on MetaCPAN:
L<https://metacpan.org/release/threads-shared>

Code repository for CPAN distribution:
L<https://github.com/Dual-Life/threads-shared>

L<threads>, L<perlthrtut>

L<http://www.perl.com/pub/a/2002/06/11/threads.html> and
L<http://www.perl.com/pub/a/2002/09/04/threads.html>

Perl threads mailing list:
L<http://lists.perl.org/list/ithreads.html>

Sample code in the I<examples> directory of this distribution on CPAN.

=head1 AUTHOR

Artur Bergman E<lt>sky AT crucially DOT netE<gt>

Documentation borrowed from the old Thread.pm.

CPAN version produced by Jerry D. Hedden E<lt>jdhedden AT cpa