use strict; use warnings; use threads; use threads::shared; use feature qw( say ); use constant NUM_THREADS => 10; my %h :shared = map { $_ => 1 } 'a'..'z'; my $size = () = keys(%h); my $done :shared; my @threads; for (1..NUM_THREADS) { push @threads, async { while (!$done) { my $test_size = () = keys(%h); if ($test_size != $size) { warn("$test_size != $size\n"); return; } } }; } sleep(10); $done = 1; $_->join() for @threads; #### 11 != 26 42 != 26 15 != 26 38 != 26 13 != 26 41 != 26 15 != 26 41 != 26 13 != 26 45 != 26