in reply to Re^11: Slow evolution of Perl = Perl is a closed Word (thread decade)
in thread Slow evolution of Perl = Perl is a closed Word

What? Care to explain that? Better still, care to demo it?

Sure, launch your favorite OS monitor and enjoy:

use strict; use warnings; use threads; $| = 1; { package foo; sub run { threads->create(sub { sleep 10 }) } } { my @a; for (1..3e6) { push @a, "foo".rand } print "memory allocated\n"; sleep 10; print "now running threads\n"; foo->run; foo->run; sleep 10; }
Only explicitly shared data gets cloned on thread creation

No, it is exactly the opposite, everything but shared data gets cloned when a thread is created.

FYI: It is perfectly possible, and reasonably simple to do non-blocking IO on a pipe under win32 without using threads. You can't use select to do it directly, but with sufficient XS/internals skills, the nitty-gritty could be hidden under the covers of Perl's select.

So, can you point me in the right direction?

  • Comment on Re^12: Slow evolution of Perl = Perl is a closed Word (thread decade)
  • Download Code

Replies are listed 'Best First'.
Re^13: Slow evolution of Perl = Perl is a closed Word (data cloning)
by tye (Sage) on Sep 04, 2007 at 17:38 UTC
    Only explicitly shared data gets cloned on thread creation
    No, it is exactly the opposite, everything but shared data gets cloned when a thread is created.

    It is my impression that unshared items get cloned but that shared items get cloned and then a third item is created to mediate between the two clones. So slightly worse in terms of efficiency of thread creation.

    - tye        

Re^13: Slow evolution of Perl = Perl is a closed Word (thread decade)
by BrowserUk (Patriarch) on Sep 05, 2007 at 00:55 UTC
    No, it is exactly the opposite,...

    You're right. I had a brain fart. Too many concurrent thought trains.

    What you need is mod://threads::Bare. Don't go looking for it because it doesn't exist (yet!). I think I have a pure perl solution that will work on win32 and may be made to work on other platforms, but it would be much better and more simply coded as a part of threads if you have the appropriate skill set and thick skin.

    So, can you point me in the right direction?

    See PeekNamedPipe and the second code snippet in Re: Non-blocking Reads from Pipe Filehandle for the (incomplete) basis to non-blocking IO from win32 anonymous pipes. There is another (older?) post around somewhere with some other details I think, but I've never had cause to completely solve the riddle from Perl.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.