I think I ruled out Dumper and STDERR cache:
#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; my %hash :shared; sub dumper { my $h = shift; my $ret = "{\n"; while (my ($k,$v) = each %$h) { $ret.= "\t$k => $v\n"; } $ret.= "}\n"; return $ret; } sub sub1 { my $str = '[s'.threads->tid()."]\n"; $str.= dumper \%hash; $str.= '[e'.threads->tid()."]\n"; return $str; } $hash{a} = 1; my $th1 = threads->new('sub1'); $hash{b} = 2; my $th2 = threads->new('sub1'); my $a = $th1->join(); my $b = $th2->join(); print STDERR $a; print STDERR $b;
Which sometimes yields:
[s1] { a => 1 b => 2 a => 1 b => 2 } [e1] [s2] { a => 1 } [e2]
And I just reproduced it on perl 5.8.5 32 and 64bit linux. Sometimes I also get:
[s1] { a => 1 b => 2 b => 2 } [e1] [s2] { a => 1 a => 1 b => 2 } [e2]
Then again, even though we see duplicate keys, their value is correct... Maybe the problem arises when trying to cycle through all keys of the hash at the exact same time its contents are being updated: If I add a select undef,undef,undef,0.01; between the two thread spawns, I never see duplicate keys. At the worst I see normal differences between $a and $b.

In reply to Re^18: does threads (still) memleak? by faxm0dem
in thread does threads (still) memleak? by faxm0dem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.