...threading little asynchronous functions whenever you need them can actually make the code run significantly slower...

Indeed. Whilst spawning a thread at the OS level is relatively fast, the non-reentrant nature of the perl runtime requires that the whole of the interpreter be replicated to avoid conflicts with global data. Whilst an effective solution to some of the problems seen with the previous pthreads implementation, it results an a substantial startup penalty. It also gives rise to some pretty fundemental caveats.

Using ithreads effectively, requires a pretty good understanding of the caveats, and designing your use of threads around them. liz covers many of these in Things you need to know before programming Perl ithreads. It's well worth a read if you intend to pursue using ithreads.

Some very clever people have done a huge amount of work to get ithreads to where they are now, but the fundemental constraint of the interpreters non-reentracy persists and is unlikely to change before Ponie hits the repositories.

As threads are a core design feature of Win32, there are many facilties of the the OS implementation that I would love to have access to from perl. The problems in gaining that access are two-fold.

  1. It would require access some of the data structures and state that the perl internals use to manage threads, which means writing patches in C or XS to expose them, which is a distinctly non-trivial task.
  2. It would entail either
    • Writing a Win32-only extension to the current ithreads api.
    • Trying to design the extensions such that they formed a generic extension that could be easily implemented on other platforms.

The former would likely gain little support from the core maintainers as it moves away from the cross-platform ideals of perl.

The latter is very difficult to do. The platform specific nature of the native Win32 threads API's combined with a host of general perl features (read: unix system features) that aren't supported or only trivially emulated on Win32, would make the task of designing a true cross-platform solution extremely hard.

I can see some ways that the current support for threads could be improved (along with the current emulations of some of the unix system concepts), but my attempts at futzing with the perl sources have been a disaster and extremely frustrating. My hat is off to those that do this regularly, they should be given medals.

All in all, I'm hoping that the ground up design of Parrot and Ponie will make the situation better before too long... and that the mouth-watering promise of P6 won't be too far away.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


In reply to Re: Re: Re: Re: Perl threads - telling them urgent stuff by BrowserUk
in thread Perl threads - telling them urgent stuff by Anonymous Monk

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.