Because I stripped down the part of my code to write a test case and kept the stupid bits that I came up with some time ago to avoid "Invalid value for shared scalar" messages without understanding why they were appearing?

Thanks a bunch I now understand my error.

For the record, I was assigning a thread object to an element of this shared hash, and using the above "strange overwriting technique" this somehow avoided the error message. Now I'm creating a "my" object reference, share it and assign it only then to the element of the shared hash.

Now this seems very complicated and I reckon I must have got lost somehow on the road. It's a bad idea to write production code whilst using modules for the first time, discovering design issues, circling back, discovering other issues... I think I'll start over ;-)

Now may I use your wisdom to get a hint on how you would design the code? Here's the big picture:

I'm simply trying to run multiple independent threads, each of which should periodically store some time-series numbers. Then a special thread would periodically take these numbers and do something with them (send them somewhere).

What I'm doing now is start the N threads plus the sending thread. Each thread handles its own infinite loop, and with its own interval. It stores its computed numbers in this shared hash. Now when the sending thread wakes up, it locks this hash, copies it to another, empties it and unlocks it. Then it can do whatever it likes with the copy


In reply to Re^12: 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.