Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by m4thieu (9274) on 2009.07.04 9:54 (#69251)

    ithreads have two problems:

    1. When you spawn a thread, it copies the whole environment from the parent thread, variables and code. This results in poor performance when a lot of libraries are loaded.

    2. You can't pass a file descriptor from one thread to the other. So you can't create a network server that spawns a thread for each client.

    This makes perl one of the only scripting language you can't use to build a multi-threaded network server, without using fancy stuff like Coro, AnyEvent or POE. Those are great libraries, but they are clumsy compared to just spawning a thread with a function to call.

    If we could fix #2, then you could spawn a server thread that sends FD to worker threads as it gets them.

    Fixing #1 could be done by allowing spawning an empty thread, giving it a module, function name and arguments to call. The new thread would only load the module once spawned, not when perl starts.

    Doing this would allow for Erlang style processes, which is basically what POE tries to do, except with a lot of mucking around with NOWAIT calls, and too many callbacks.

    • C:\Projekte\App-CPANr>perl -Mthreads -e "open my $fh, '<', '/boot.ini'; for (async { print for <$fh>}, async{sleep 10}) { $_->join; }"

      [boot loader]
      timeout=30
      default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
      [opera ting systems]
      multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional"
      /fastdetect /NoExecute=OptIn

      • Works great for that. How about starting ten threads, then passing them a filehandle to work on? That's what I was talking about.

        Beside, if you have a lot of stuff loaded (like POE), instead of this trivial exemple, each thread spawn is rather costly.

    • 1. When you spawn a thread, it copies the whole environment from the parent thread, variables and code. This results in poor performance when a lot of libraries are loaded.

      The worst part of this is not just the poor performance but its unpredictability and that the effect is not local but global.

      For instance, to implement a CPAN module doing something specific (as downloading a bunch of files from the Internet in parallel) that you want to be usable from any script, if the module were launching, say, 10