Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

We are using ActiveState Perl 5.6 in our shop.

I have read in several places, for instance in this thread, that the ActiveState Perl 'simulates' forking by using threads. I have a lot of personal experience in writing multi-threaded code in classical 'C'. (Classical, as opposed to C++.) That was under OS/2 (R.I.P.) so it was a while ago and I may not remember everything absolutely correct but I think the following is true.

  • In a truly fork'ed application, each pid becomes a separate process and is in fact a copy of the parent application. To share information (events or data) between the pids, some kind of IPC must be used.
  • In a threaded application this is not the fact, but global resources are shared between all threads and must be protected, normally using semaphores. Events and non-global data must be shared using pipes, queues or other IPC mechanisms. When compiling a truly threaded application in C, the compiler 'promises' that stack variables in each C function will be unique to the function instance executed. If two or more threads execute the same C function simultaneously they will share the code, but not the stack variables.
I then started to think. And this is when it got hairy...
  • Can a sub my_complicated_calculation(){} be used by more than one simulated forked process, actually implemented as threads in AS Perl?
  • Isn't there a risk that the 'my' variables in that common sub will be overwritten if my_complicated_calculation() is concurrently called from two or more threads?
  • What about global variables?
  • Is this all taken care of by the Perl interpreter, or do we have an issue here migrating a forking Perl application from UNIX to Win-32?

Everything went worng, just as foreseen.

In reply to ActiveState, threaded fork and re-entrancy by Biker

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (2)
    As of 2018-07-18 22:49 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (397 votes). Check out past polls.