Greetings.
I have an app that collects some data every few seconds, and once about a minute draws graph of them. The problem is that drawing the graph sometimes takes enough time to lose a round of data collection. So I wanted to run the drawing sub asynchronously and decided, that this will be easier done with ithreads than with forks. As it doesn't need any communication with the main program after getting the argumets, the snippet looks real easy:
use threads; ... threads->create(\&draw, arg1, arg2, ...)->detach(); ...
But this creates problems. It happened to die with: *** glibc detected *** double free or corruption (fasttop): 0xb7e8d7d8 ***. It also sometimes happens, that the draw sub gets malformed args, what hasn't happened since months. But ultimately, even if everything ticks otherwise, after executing draw a few times the program just exits without goodbye! Now I don't know, is it something fundamental that I've missed, or the draw function somehow isn't thread safe, or ufo decided to disturb me.
For further detail: in fact in some moments there can be as much as 35 drawing threads created in a short time, but it never really stood up to even ten. The draw function is RRDs::graph, and I'm using perl 5.8.6.
--
Someday, people who know how to use computers will rule over those who don't. And there will be a special name for them: secretaries. -Dilbert quote

In reply to Running subs ,,in background'' by lRem

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.