I have recently been through the process of coding two rather large private perl projects where I really, really, *wanted* to use threads from perl, because a threaded model mapped very well to my problem space. So let me tell you what I found out during those projects, and what I wish for:

1) Perl ithreads are only just starting to stabilize. If you expect your installed base to include Bob's Old Redhat Box with perl 5.8.0 (or worse, 5.6.x on it), just forget about threads right now and save yourself a lot of greif.

2) perldoc perlthrtut has a section that concludes with a very important statement: "Perl Threads Are Different.". All I really wanted was POSIX-style threads. I was prepared to properly deal with locking and mutexes and the whole nine yards. My Operating System supports POSIX-style threads in C, but perl's threading is a completely different beast. I'm sure it was done this way in some hope of having nearly-identical threading behavior across a wide array of underlying threads implementations, but I have to conclude that it sucks.

At many times during the 2nd project, I seriously considered just starting over in C and building up some libraries and macros to make the code nearly as compact as perl, and using some standard regex library to make up for that part. In the end the compromise I ended up making (in both cases) was to use a multi-process model and "share" data via freeze/thaw over the top of various IPC mechanisms (sysv shm, semaphores, disk files w/ locks - at one point I even invented my own perl message queueing module to handle inter-process message-passing with disk-persistence).

The whole thing left a bad taste in my mouth. My projects are considerably less efficient at what they do than they would have been if ithreads had turned out to be what I hoped it was - a mirror of the underlying posix threads layers.

What do I want out of perl threading?

I want all data to be shared by default when a thread spawns from another.

I want to be forced to explicitly declare thread-local storage.

If you're going to force me to explicitly share data, I want shared data to be transparent and completely functional. Doing share($x), and finding that $x->{foo}->{bar}->[3]->{zip} is not in fact shared, sucks.

I want POSIX threading, exposed through perl, to operate basically just like it does in C.

Is it so much to ask for?


In reply to Re: Threading vs perl by ph713
in thread Threading vs perl by Eyck

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.