Lines Matching refs:shared

1 package threads::shared;
16 $threads::shared::threads_shared = 1;
19 $threads::shared::clone_warn = undef;
24 XSLoader::load('threads::shared', $XS_VERSION);
70 sub threads::shared::tie::SPLICE
73 Carp::croak('Splice not implemented for shared arrays');
77 # Create a thread-shared clone of a complex data structure or object
98 # 2. Already shared; or
116 # Make empty shared array ref
126 # Make empty shared hash ref
163 if (! defined($threads::shared::clone_warn)) {
165 } elsif ($threads::shared::clone_warn) {
195 threads::shared - Perl extension for sharing data structures between threads
199 This document describes threads::shared version 1.68
204 use threads::shared;
206 my $var :shared;
207 my %hsh :shared;
208 my @ary :shared;
237 my $lockvar :shared;
268 C<share> takes a variable and marks it as shared:
275 C<share> will return the shared rvalue, but always as a reference.
277 Variables can also be marked as shared at compile time by using the
278 C<:shared> attribute:
280 my ($var, %hash, @array) :shared;
282 Shared variables can only store scalars, refs of shared variables, or
283 refs of shared data (discussed in next section):
285 my ($var, %hash, @array) :shared;
293 # Storing shared refs
299 # $var = \$bork; # ref of non-shared variable
300 # $hash{'bork'} = []; # non-shared array ref
301 # push(@array, { 'x' => 1 }); # non-shared hash ref
305 C<shared_clone> takes a reference, and returns a shared version of its
306 argument, performing a deep copy on any non-shared elements. Any shared
327 $threads::shared::clone_warn = 1;
332 $threads::shared::clone_warn = 0;
338 C<is_shared> checks if the specified variable is shared or not. If shared,
343 print("\$var is shared\n");
345 print("\$var is not shared\n");
349 specified element belongs to a shared array or hash. (It does not check
352 my %hash :shared;
354 print("\%hash is shared\n");
359 print("\$hash{'elem'} is in a shared hash\n");
372 my %hash :shared;
380 my $var :shared;
393 my %hash :shared;
398 If you need more fine-grained control over shared variable access, see
417 In its second form, C<cond_wait> takes a shared, B<unlocked> variable followed
418 by a shared, B<locked> variable. The second variable is unlocked and thread
424 requirement is not fulfilled. For example, to pause until a shared counter
440 Like C<cond_wait>, this function may take a shared, B<locked> variable as an
486 L<threads::shared> exports a version of L<bless()|perlfunc/"bless REF"> that
487 works on shared objects such that I<blessings> propagate across threads.
489 # Create a shared 'Foo' object
490 my $foo :shared = shared_clone({});
493 # Create a shared 'Bar' object
494 my $bar :shared = shared_clone({});
521 L<threads::shared> is designed to disable itself silently if threads are not
526 C<use threads::shared>. L<threads> will emit a warning if you use it after
527 L<threads::shared>.
559 Therefore, populate such variables B<after> declaring them as shared. (Scalar
562 Blessing a shared item after it has been nested in another shared item does
563 not propagate the blessing to the shared reference:
574 written to support sharing. For example, a shared object's destructor may
576 get called at all if it is embedded inside another shared object. Another
590 Taking references to the elements of shared arrays and hashes does not
591 autovivify the elements, and neither does slicing a shared array/hash over
596 C<< $hashref->{key} >> or C<< $arrayref->[idx] >> is B<not> shared, causing
597 the error "lock can only be used on shared values" to occur when you attempt
602 whether or not two shared references are equivalent (e.g., when testing for
606 use threads::shared;
609 # If ref is shared, use threads::shared's internal ID.
618 L<each()|perlfunc/"each HASH"> does not work properly on shared references
619 embedded in shared structures. For example:
621 my %foo :shared;
645 my $errno :shared = dualvar($!,$!);
648 to: L<http://rt.cpan.org/Public/Dist/Display.html?Name=threads-shared>
652 threads::shared on MetaCPAN:
653 L<https://metacpan.org/release/threads-shared>
656 L<https://github.com/Dual-Life/threads-shared>
678 threads::shared is released under the same license as Perl.