summaryrefslogtreecommitdiffstats
path: root/upstream/mageia-cauldron/man3pm/threads::shared.3pm
blob: ea4d20ed38f1b42d108e082ebd0a283758a5fd02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "threads::shared 3pm"
.TH threads::shared 3pm 2023-11-28 "perl v5.38.2" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
threads::shared \- Perl extension for sharing data structures between threads
.SH VERSION
.IX Header "VERSION"
This document describes threads::shared version 1.68
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 2
\&  use threads;
\&  use threads::shared;
\&
\&  my $var :shared;
\&  my %hsh :shared;
\&  my @ary :shared;
\&
\&  my ($scalar, @array, %hash);
\&  share($scalar);
\&  share(@array);
\&  share(%hash);
\&
\&  $var = $scalar_value;
\&  $var = $shared_ref_value;
\&  $var = shared_clone($non_shared_ref_value);
\&  $var = shared_clone({\*(Aqfoo\*(Aq => [qw/foo bar baz/]});
\&
\&  $hsh{\*(Aqfoo\*(Aq} = $scalar_value;
\&  $hsh{\*(Aqbar\*(Aq} = $shared_ref_value;
\&  $hsh{\*(Aqbaz\*(Aq} = shared_clone($non_shared_ref_value);
\&  $hsh{\*(Aqquz\*(Aq} = shared_clone([1..3]);
\&
\&  $ary[0] = $scalar_value;
\&  $ary[1] = $shared_ref_value;
\&  $ary[2] = shared_clone($non_shared_ref_value);
\&  $ary[3] = shared_clone([ {}, [] ]);
\&
\&  { lock(%hash); ...  }
\&
\&  cond_wait($scalar);
\&  cond_timedwait($scalar, time() + 30);
\&  cond_broadcast(@array);
\&  cond_signal(%hash);
\&
\&  my $lockvar :shared;
\&  # condition var != lock var
\&  cond_wait($var, $lockvar);
\&  cond_timedwait($var, time()+30, $lockvar);
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
By default, variables are private to each thread, and each newly created
thread gets a private copy of each existing variable.  This module allows you
to share variables across different threads (and pseudo-forks on Win32).  It
is used together with the threads module.
.PP
This module supports the sharing of the following data types only:  scalars
and scalar refs, arrays and array refs, and hashes and hash refs.
.SH EXPORT
.IX Header "EXPORT"
The following functions are exported by this module: \f(CW\*(C`share\*(C'\fR,
\&\f(CW\*(C`shared_clone\*(C'\fR, \f(CW\*(C`is_shared\*(C'\fR, \f(CW\*(C`cond_wait\*(C'\fR, \f(CW\*(C`cond_timedwait\*(C'\fR, \f(CW\*(C`cond_signal\*(C'\fR
and \f(CW\*(C`cond_broadcast\*(C'\fR
.PP
Note that if this module is imported when threads has not yet been loaded,
then these functions all become no-ops.  This makes it possible to write
modules that will work in both threaded and non-threaded environments.
.SH FUNCTIONS
.IX Header "FUNCTIONS"
.IP "share VARIABLE" 4
.IX Item "share VARIABLE"
\&\f(CW\*(C`share\*(C'\fR takes a variable and marks it as shared:
.Sp
.Vb 4
\&  my ($scalar, @array, %hash);
\&  share($scalar);
\&  share(@array);
\&  share(%hash);
.Ve
.Sp
\&\f(CW\*(C`share\*(C'\fR will return the shared rvalue, but always as a reference.
.Sp
Variables can also be marked as shared at compile time by using the
\&\f(CW\*(C`:shared\*(C'\fR attribute:
.Sp
.Vb 1
\&  my ($var, %hash, @array) :shared;
.Ve
.Sp
Shared variables can only store scalars, refs of shared variables, or
refs of shared data (discussed in next section):
.Sp
.Vb 2
\&  my ($var, %hash, @array) :shared;
\&  my $bork;
\&
\&  # Storing scalars
\&  $var = 1;
\&  $hash{\*(Aqfoo\*(Aq} = \*(Aqbar\*(Aq;
\&  $array[0] = 1.5;
\&
\&  # Storing shared refs
\&  $var = \e%hash;
\&  $hash{\*(Aqary\*(Aq} = \e@array;
\&  $array[1] = \e$var;
\&
\&  # The following are errors:
\&  #   $var = \e$bork;                    # ref of non\-shared variable
\&  #   $hash{\*(Aqbork\*(Aq} = [];               # non\-shared array ref
\&  #   push(@array, { \*(Aqx\*(Aq => 1 });       # non\-shared hash ref
.Ve
.IP "shared_clone REF" 4
.IX Item "shared_clone REF"
\&\f(CW\*(C`shared_clone\*(C'\fR takes a reference, and returns a shared version of its
argument, performing a deep copy on any non-shared elements.  Any shared
elements in the argument are used as is (i.e., they are not cloned).
.Sp
.Vb 1
\&  my $cpy = shared_clone({\*(Aqfoo\*(Aq => [qw/foo bar baz/]});
.Ve
.Sp
Object status (i.e., the class an object is blessed into) is also cloned.
.Sp
.Vb 4
\&  my $obj = {\*(Aqfoo\*(Aq => [qw/foo bar baz/]};
\&  bless($obj, \*(AqFoo\*(Aq);
\&  my $cpy = shared_clone($obj);
\&  print(ref($cpy), "\en");         # Outputs \*(AqFoo\*(Aq
.Ve
.Sp
For cloning empty array or hash refs, the following may also be used:
.Sp
.Vb 2
\&  $var = &share([]);   # Same as $var = shared_clone([]);
\&  $var = &share({});   # Same as $var = shared_clone({});
.Ve
.Sp
Not all Perl data types can be cloned (e.g., globs, code refs).  By default,
\&\f(CW\*(C`shared_clone\*(C'\fR will croak if it encounters such items.  To change
this behaviour to a warning, then set the following:
.Sp
.Vb 1
\&  $threads::shared::clone_warn = 1;
.Ve
.Sp
In this case, \f(CW\*(C`undef\*(C'\fR will be substituted for the item to be cloned.  If
set to zero:
.Sp
.Vb 1
\&  $threads::shared::clone_warn = 0;
.Ve
.Sp
then the \f(CW\*(C`undef\*(C'\fR substitution will be performed silently.
.IP "is_shared VARIABLE" 4
.IX Item "is_shared VARIABLE"
\&\f(CW\*(C`is_shared\*(C'\fR checks if the specified variable is shared or not.  If shared,
returns the variable's internal ID (similar to
\&\f(CWrefaddr()\fR (see Scalar::Util).  Otherwise, returns \f(CW\*(C`undef\*(C'\fR.
.Sp
.Vb 5
\&  if (is_shared($var)) {
\&      print("\e$var is shared\en");
\&  } else {
\&      print("\e$var is not shared\en");
\&  }
.Ve
.Sp
When used on an element of an array or hash, \f(CW\*(C`is_shared\*(C'\fR checks if the
specified element belongs to a shared array or hash.  (It does not check
the contents of that element.)
.Sp
.Vb 4
\&  my %hash :shared;
\&  if (is_shared(%hash)) {
\&      print("\e%hash is shared\en");
\&  }
\&
\&  $hash{\*(Aqelem\*(Aq} = 1;
\&  if (is_shared($hash{\*(Aqelem\*(Aq})) {
\&      print("\e$hash{\*(Aqelem\*(Aq} is in a shared hash\en");
\&  }
.Ve
.IP "lock VARIABLE" 4
.IX Item "lock VARIABLE"
\&\f(CW\*(C`lock\*(C'\fR places a \fBadvisory\fR lock on a variable until the lock goes out of
scope.  If the variable is locked by another thread, the \f(CW\*(C`lock\*(C'\fR call will
block until it's available.  Multiple calls to \f(CW\*(C`lock\*(C'\fR by the same thread from
within dynamically nested scopes are safe \-\- the variable will remain locked
until the outermost lock on the variable goes out of scope.
.Sp
\&\f(CW\*(C`lock\*(C'\fR follows references exactly \fIone\fR level:
.Sp
.Vb 3
\&  my %hash :shared;
\&  my $ref = \e%hash;
\&  lock($ref);           # This is equivalent to lock(%hash)
.Ve
.Sp
Note that you cannot explicitly unlock a variable; you can only wait for the
lock to go out of scope.  This is most easily accomplished by locking the
variable inside a block.
.Sp
.Vb 7
\&  my $var :shared;
\&  {
\&      lock($var);
\&      # $var is locked from here to the end of the block
\&      ...
\&  }
\&  # $var is now unlocked
.Ve
.Sp
As locks are advisory, they do not prevent data access or modification by
another thread that does not itself attempt to obtain a lock on the variable.
.Sp
You cannot lock the individual elements of a container variable:
.Sp
.Vb 4
\&  my %hash :shared;
\&  $hash{\*(Aqfoo\*(Aq} = \*(Aqbar\*(Aq;
\&  #lock($hash{\*(Aqfoo\*(Aq});          # Error
\&  lock(%hash);                  # Works
.Ve
.Sp
If you need more fine-grained control over shared variable access, see
Thread::Semaphore.
.IP "cond_wait VARIABLE" 4
.IX Item "cond_wait VARIABLE"
.PD 0
.IP "cond_wait CONDVAR, LOCKVAR" 4
.IX Item "cond_wait CONDVAR, LOCKVAR"
.PD
The \f(CW\*(C`cond_wait\*(C'\fR function takes a \fBlocked\fR variable as a parameter, unlocks
the variable, and blocks until another thread does a \f(CW\*(C`cond_signal\*(C'\fR or
\&\f(CW\*(C`cond_broadcast\*(C'\fR for that same locked variable.  The variable that
\&\f(CW\*(C`cond_wait\*(C'\fR blocked on is re-locked after the \f(CW\*(C`cond_wait\*(C'\fR is satisfied.  If
there are multiple threads \f(CW\*(C`cond_wait\*(C'\fRing on the same variable, all but one
will re-block waiting to reacquire the
lock on the variable.  (So if you're only
using \f(CW\*(C`cond_wait\*(C'\fR for synchronization, give up the lock as soon as possible).
The two actions of unlocking the variable and entering the blocked wait state
are atomic, the two actions of exiting from the blocked wait state and
re-locking the variable are not.
.Sp
In its second form, \f(CW\*(C`cond_wait\*(C'\fR takes a shared, \fBunlocked\fR variable followed
by a shared, \fBlocked\fR variable.  The second variable is unlocked and thread
execution suspended until another thread signals the first variable.
.Sp
It is important to note that the variable can be notified even if no thread
\&\f(CW\*(C`cond_signal\*(C'\fR or \f(CW\*(C`cond_broadcast\*(C'\fR on the variable.  It is therefore
important to check the value of the variable and go back to waiting if the
requirement is not fulfilled.  For example, to pause until a shared counter
drops to zero:
.Sp
.Vb 1
\&  { lock($counter); cond_wait($counter) until $counter == 0; }
.Ve
.IP "cond_timedwait VARIABLE, ABS_TIMEOUT" 4
.IX Item "cond_timedwait VARIABLE, ABS_TIMEOUT"
.PD 0
.IP "cond_timedwait CONDVAR, ABS_TIMEOUT, LOCKVAR" 4
.IX Item "cond_timedwait CONDVAR, ABS_TIMEOUT, LOCKVAR"
.PD
In its two-argument form, \f(CW\*(C`cond_timedwait\*(C'\fR takes a \fBlocked\fR variable and an
absolute timeout in \fIepoch\fR seconds (see \fBtime()\fR in perlfunc
for more) as parameters, unlocks the variable, and blocks until the
timeout is reached or another thread signals the variable.  A false value is
returned if the timeout is reached, and a true value otherwise.  In either
case, the variable is re-locked upon return.
.Sp
Like \f(CW\*(C`cond_wait\*(C'\fR, this function may take a shared, \fBlocked\fR variable as an
additional parameter; in this case the first parameter is an \fBunlocked\fR
condition variable protected by a distinct lock variable.
.Sp
Again like \f(CW\*(C`cond_wait\*(C'\fR, waking up and reacquiring the lock are not atomic,
and you should always check your desired condition after this function
returns.  Since the timeout is an absolute value, however, it does not have to
be recalculated with each pass:
.Sp
.Vb 6
\&  lock($var);
\&  my $abs = time() + 15;
\&  until ($ok = desired_condition($var)) {
\&      last if !cond_timedwait($var, $abs);
\&  }
\&  # we got it if $ok, otherwise we timed out!
.Ve
.IP "cond_signal VARIABLE" 4
.IX Item "cond_signal VARIABLE"
The \f(CW\*(C`cond_signal\*(C'\fR function takes a \fBlocked\fR variable as a parameter and
unblocks one thread that's \f(CW\*(C`cond_wait\*(C'\fRing
on that variable.  If more than one
thread is blocked in a \f(CW\*(C`cond_wait\*(C'\fR on that variable, only one (and which one
is indeterminate) will be unblocked.
.Sp
If there are no threads blocked in a \f(CW\*(C`cond_wait\*(C'\fR on the variable, the signal
is discarded.  By always locking before
signaling, you can (with care), avoid
signaling before another thread has entered \fBcond_wait()\fR.
.Sp
\&\f(CW\*(C`cond_signal\*(C'\fR will normally generate a warning if you attempt to use it on an
unlocked variable.  On the rare occasions
where doing this may be sensible, you
can suppress the warning with:
.Sp
.Vb 1
\&  { no warnings \*(Aqthreads\*(Aq; cond_signal($foo); }
.Ve
.IP "cond_broadcast VARIABLE" 4
.IX Item "cond_broadcast VARIABLE"
The \f(CW\*(C`cond_broadcast\*(C'\fR function works similarly to \f(CW\*(C`cond_signal\*(C'\fR.
\&\f(CW\*(C`cond_broadcast\*(C'\fR, though, will unblock \fBall\fR the threads that are blocked in
a \f(CW\*(C`cond_wait\*(C'\fR on the locked variable, rather than only one.
.SH OBJECTS
.IX Header "OBJECTS"
threads::shared exports a version of \fBbless()\fR that
works on shared objects such that \fIblessings\fR propagate across threads.
.PP
.Vb 3
\&  # Create a shared \*(AqFoo\*(Aq object
\&  my $foo :shared = shared_clone({});
\&  bless($foo, \*(AqFoo\*(Aq);
\&
\&  # Create a shared \*(AqBar\*(Aq object
\&  my $bar :shared = shared_clone({});
\&  bless($bar, \*(AqBar\*(Aq);
\&
\&  # Put \*(Aqbar\*(Aq inside \*(Aqfoo\*(Aq
\&  $foo\->{\*(Aqbar\*(Aq} = $bar;
\&
\&  # Rebless the objects via a thread
\&  threads\->create(sub {
\&      # Rebless the outer object
\&      bless($foo, \*(AqYin\*(Aq);
\&
\&      # Cannot directly rebless the inner object
\&      #bless($foo\->{\*(Aqbar\*(Aq}, \*(AqYang\*(Aq);
\&
\&      # Retrieve and rebless the inner object
\&      my $obj = $foo\->{\*(Aqbar\*(Aq};
\&      bless($obj, \*(AqYang\*(Aq);
\&      $foo\->{\*(Aqbar\*(Aq} = $obj;
\&
\&  })\->join();
\&
\&  print(ref($foo),          "\en");    # Prints \*(AqYin\*(Aq
\&  print(ref($foo\->{\*(Aqbar\*(Aq}), "\en");    # Prints \*(AqYang\*(Aq
\&  print(ref($bar),          "\en");    # Also prints \*(AqYang\*(Aq
.Ve
.SH NOTES
.IX Header "NOTES"
threads::shared is designed to disable itself silently if threads are not
available.  This allows you to write modules and packages that can be used
in both threaded and non-threaded applications.
.PP
If you want access to threads, you must \f(CW\*(C`use threads\*(C'\fR before you
\&\f(CW\*(C`use threads::shared\*(C'\fR.  threads will emit a warning if you use it after
threads::shared.
.SH WARNINGS
.IX Header "WARNINGS"
.IP "\fBcond_broadcast()\fR called on unlocked variable" 4
.IX Item "cond_broadcast() called on unlocked variable"
.PD 0
.IP "\fBcond_signal()\fR called on unlocked variable" 4
.IX Item "cond_signal() called on unlocked variable"
.PD
See "cond_signal VARIABLE", above.
.SH "BUGS AND LIMITATIONS"
.IX Header "BUGS AND LIMITATIONS"
When \f(CW\*(C`share\*(C'\fR is used on arrays, hashes, array refs or hash refs, any data
they contain will be lost.
.PP
.Vb 3
\&  my @arr = qw(foo bar baz);
\&  share(@arr);
\&  # @arr is now empty (i.e., == ());
\&
\&  # Create a \*(Aqfoo\*(Aq object
\&  my $foo = { \*(Aqdata\*(Aq => 99 };
\&  bless($foo, \*(Aqfoo\*(Aq);
\&
\&  # Share the object
\&  share($foo);        # Contents are now wiped out
\&  print("ERROR: \e$foo is empty\en")
\&      if (! exists($foo\->{\*(Aqdata\*(Aq}));
.Ve
.PP
Therefore, populate such variables \fBafter\fR declaring them as shared.  (Scalar
and scalar refs are not affected by this problem.)
.PP
Blessing a shared item after it has been nested in another shared item does
not propagate the blessing to the shared reference:
.PP
.Vb 5
\&  my $foo = &share({});
\&  my $bar = &share({});
\&  $bar\->{foo} = $foo;
\&  bless($foo, \*(Aqbaz\*(Aq);   # $foo is now of class \*(Aqbaz\*(Aq,
\&                        # but $bar\->{foo} is unblessed.
.Ve
.PP
Therefore, you should bless objects before sharing them.
.PP
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 \fIexamples/class.pl\fR (in the CPAN
distribution of this module) for how to create a class that supports object
sharing.
.PP
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.
.PP
Does not support \f(CW\*(C`splice\*(C'\fR on arrays.  Does not support explicitly changing
array lengths via $#array \-\- use \f(CW\*(C`push\*(C'\fR and \f(CW\*(C`pop\*(C'\fR instead.
.PP
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.
.PP
\&\f(CWshare()\fR allows you to \f(CWshare($hashref\->{key})\fR and
\&\f(CWshare($arrayref\->[idx])\fR without giving any error message.  But the
\&\f(CW\*(C`$hashref\->{key}\*(C'\fR or \f(CW\*(C`$arrayref\->[idx]\*(C'\fR is \fBnot\fR shared, causing
the error "lock can only be used on shared values" to occur when you attempt
to \f(CWlock($hashref\->{key})\fR or \f(CWlock($arrayref\->[idx])\fR in another
thread.
.PP
Using \f(CWrefaddr()\fR is unreliable for testing
whether or not two shared references are equivalent (e.g., when testing for
circular references).  Use \fBis_shared()\fR, instead:
.PP
.Vb 3
\&    use threads;
\&    use threads::shared;
\&    use Scalar::Util qw(refaddr);
\&
\&    # If ref is shared, use threads::shared\*(Aqs 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
\&    }
.Ve
.PP
\&\fBeach()\fR does not work properly on shared references
embedded in shared structures.  For example:
.PP
.Vb 2
\&    my %foo :shared;
\&    $foo{\*(Aqbar\*(Aq} = shared_clone({\*(Aqa\*(Aq=>\*(Aqx\*(Aq, \*(Aqb\*(Aq=>\*(Aqy\*(Aq, \*(Aqc\*(Aq=>\*(Aqz\*(Aq});
\&
\&    while (my ($key, $val) = each(%{$foo{\*(Aqbar\*(Aq}})) {
\&        ...
\&    }
.Ve
.PP
Either of the following will work instead:
.PP
.Vb 4
\&    my $ref = $foo{\*(Aqbar\*(Aq};
\&    while (my ($key, $val) = each(%{$ref})) {
\&        ...
\&    }
\&
\&    foreach my $key (keys(%{$foo{\*(Aqbar\*(Aq}})) {
\&        my $val = $foo{\*(Aqbar\*(Aq}{$key};
\&        ...
\&    }
.Ve
.PP
This module supports dual-valued variables created using \f(CWdualvar()\fR from
Scalar::Util.  However, while \f(CW$!\fR acts
like a dualvar, it is implemented as a tied SV.  To propagate its value, use
the follow construct, if needed:
.PP
.Vb 1
\&    my $errno :shared = dualvar($!,$!);
.Ve
.PP
View existing bug reports at, and submit any new bugs, problems, patches, etc.
to: <http://rt.cpan.org/Public/Dist/Display.html?Name=threads\-shared>
.SH "SEE ALSO"
.IX Header "SEE ALSO"
threads::shared on MetaCPAN:
<https://metacpan.org/release/threads\-shared>
.PP
Code repository for CPAN distribution:
<https://github.com/Dual\-Life/threads\-shared>
.PP
threads, perlthrtut
.PP
<http://www.perl.com/pub/a/2002/06/11/threads.html> and
<http://www.perl.com/pub/a/2002/09/04/threads.html>
.PP
Perl threads mailing list:
<http://lists.perl.org/list/ithreads.html>
.PP
Sample code in the \fIexamples\fR directory of this distribution on CPAN.
.SH AUTHOR
.IX Header "AUTHOR"
Artur Bergman <sky AT crucially DOT net>
.PP
Documentation borrowed from the old Thread.pm.
.PP
CPAN version produced by Jerry D. Hedden <jdhedden AT cpan DOT org>.
.SH LICENSE
.IX Header "LICENSE"
threads::shared is released under the same license as Perl.