#!/usr/bin/env perl6 # my %shared_hash; await do for 1..10 -> $thread { start { for 1..100_000 -> $loop { my $key = floor(rand * 10_000); my $ref := %shared_hash<$key>; if !$ref { $ref = 0; } %shared_hash{$key} = $ref + 1; } } } say "shared_hash has ", %shared_hash.keys.elems, " keys"; # Don't know how to do this easily. Is there an average function somewhere? my $sum = 0; for %shared_hash.values -> $v { $sum += $v; } my $ave = $sum / %shared_hash.keys.elems; say "Average value (~10 if threadsafe): ", $ave; #### $ perl6 killit.p6 shared_hash has 10001 keys Average value (~10 if threadsafe): 0.999900 #### $ perl6 killit.p6 *** Error in `/home/jeff/perl6/bin/moar': double free or corruption (!prev): 0x00002ad5b0147070 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x2ad5a8b3c7e5] /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x2ad5a8b4537a] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x2ad5a8b4953c] //home/jeff/perl6/lib/libmoar.so(+0x2266af)[0x2ad5a838b6af] [0x2ad5aa6f1ce8] ======= Memory map: ======== 00400000-00402000 r-xp 00000000 fc:09 888145 /home/jeff/perl6/bin/moar 00602000-00603000 r--p 00002000 fc:09 888145 /home/jeff/perl6/bin/moar 00603000-00604000 rw-p 00003000 fc:09 888145 /home/jeff/perl6/bin/moar 00a4f000-039f1000 rw-p 00000000 00:00 0 [heap] ...