Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Threading vs perl

by ph713 (Pilgrim)
on Jun 24, 2005 at 21:06 UTC ( [id://469825]=note: print w/replies, xml ) Need Help??


in reply to Threading vs perl

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?

Replies are listed 'Best First'.
Re^2: Threading vs perl
by BrowserUk (Patriarch) on Jun 27, 2005 at 12:40 UTC
    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.

    You mention using 5.6.1. The threading model exposed in 5.6.1 is almost exactly what you say you want. A thin veneer over the POSIX threads API. Everything shared by default. Full access to all of the POSIX locking and mutex functions.

    My suggestion to you, is to try writing one or two mildly complex applications using 5.6.1. This is the only way that you will see and understand the difficulties involved in trying to translate the techniques that you would employ using this api at the C level into programs that also have to contend with the realities of Perl's "fat" internal datastructures and inherently non-reentrant core apis.

    Only then will you understand that you don't want what you think you want.


    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".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re^2: Threading vs perl
by etcshadow (Priest) on Jun 24, 2005 at 23:57 UTC
    Precisely. So well stated, that I don't think I could add a damn thing. One of those instances when I wish that there were a mechanism to convert 10 votes into a +2 or 40 votes into a +3.
    ------------ :Wq Not an editor command: Wq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://469825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found