In general, the "non-reentrance" problem is only limited to a single process (i.e. an interrupt in one process will have no effect on another process, unless of-course the process is the kernel or some other really important piece of code).

The easiest way to think about it is to consider function foo that uses a global variable (bar) to store some data. Now if foo is being called and has modified bar, and foo is called again (by the same process) before its first invocation is done bar may not be set properly and could cause foo to behave abnormally (the "totally confused and crashing" effect mentioned in "Advanced Perl Programming"). In most cases it will just cause a program error, but malloc is such so intimate w/ the system that a problem there could lead to overlapping blocks of allocated memory w/ another process, etc...

Consider this (really bogus, but demonstrates the point) example:

my $bar; sub foo{ $bar=time(); sleep 5; return $bar+20; }
(for this example, pretend that signals don't mess up sleep calls, even though they do) Now when foo is called it will sleep for 5 seconds and return a time 20 seconds after it was called.. However, if foo were called, and during the sleep a signal caused foo to be called again the program wouldn't crash, but the first foo would return a wrong value (a value different from what it would have returned it it had not been interrupted).

In non-threaded programming this problem is pretty-much limited to signal and exception handlers. However when you're dealing w/ a threaded application you need to be very careful about possible code reentrance.

In general in signal handlers you should not be doing much work.


Les Howard
www.lesandchris.com
Author of Net::Syslog and Number::Spell


In reply to Re: Malloc is not reentrant? by lhoward
in thread Malloc is not reentrant? by floopy

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.