There is a lot of misinformation around.

perlthrtut was originally written about/relating to perl5005 threads, and has barely been revised since their demise in favour of iThreads.

Further, a lot of the casual advise available in reference to concurrency in Perl is dispensed by people who have made little or no attempt to utilise iThreads in any meaningful way, and is often coloured by experiences born of early 5005threading over early versions of *nix pthreads libraries, before they had figured out how to properly resolve threading and forking.

Using forking and threading in the same program does complicate matters. For example, what should happen if you call fork within a process that has 3 running threads?

Under win32, calling system within a thread process is a perfectly safe thing to do as it doesn't use fork, or attempt to perform any cloning of the original process.

On other systems you will need to understand the function and limitations of the underlying OS threading libraries, and their interaction with the iThread implementation on your systems. There seems to be little or no information available regarding this in conjunction with *nix systems.

Basically, Perl threading has been so deamonised, that there are many areas of it's operation that have never been explored. If you are writing code for immediate production use, then you should probably avoid using a threads + fork combination as you would be trailblazing and may well encounter latent bugs and need to wait for several builds before fixes would become available.

If your program is less urgent and you have the will to explore the possibilities, especially if you would then be able to pass on your experiences, it's possible that the combination could be used to good effect and could benefit the wider community.

In either case, if you posted a description of the program you are going to write, and where you intend to use threads and fork, then you may well get some good advise on one or more ways of tackling the problem both with and without using threads.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Using forks and threads by BrowserUk
in thread Using forks and threads by ColinHorne

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.