what is the best choose fork or thread?

Discussion in 'Perl Misc' started by sonet, Nov 23, 2006.

  1. sonet

    sonet Guest

    I have a project must send a lot of file in win2k at the same time.
    But what is the best method in win32?
    Can the perl build-in function fork work in win32?
    Or the perl build-in thread is good solution
     
    sonet, Nov 23, 2006
    #1
    1. Advertising

  2. sonet

    -berlin.de Guest

    sonet <> wrote in comp.lang.perl.misc:
    > I have a project must send a lot of file in win2k at the same time.
    > But what is the best method in win32?
    > Can the perl build-in function fork work in win32?
    > Or the perl build-in thread is good solution


    Who knows? Your problem description is too vague for a meaningful
    answer.

    fork() works on win32, but is implemented in terms of threads. Choose
    the one whose interface matches your needs best, the base mechanism will
    be the same in any case.

    Anno
     
    -berlin.de, Nov 23, 2006
    #2
    1. Advertising

  3. On Thu, 23 Nov 2006 23:56:42 +0800, sonet wrote:

    > I have a project must send a lot of file in win2k at the same time.
    > But what is the best method in win32?
    > Can the perl build-in function fork work in win32?
    > Or the perl build-in thread is good solution


    Besides Anno's answer, be aware that threads have severe limitations. More
    to the point, threads and signals don't mix. So if you need timeouts (in
    Perl) or any other signal handling, you are pretty much stuck on forking.

    Other than that, in general threads are faster than forks. New threads are
    created faster and interthread/process communication is generally faster.
    However on Windows, forks are implemented as threads (according to Anno)
    so the equation may be different on Windows.

    Now you say that this is about "a lot of file". Do you mean transfers of
    big files? In that case the transfer time is likely to swamp any
    difference between threads and forks, as long as the threads/processes
    don't need to communicate much.

    The best answer may be to try it out.

    HTH,
    M4
    --
    Redundancy is a great way to introduce more single points of failure.
     
    Martijn Lievaart, Nov 23, 2006
    #3
  4. sonet

    Ben Morrow Guest

    Quoth Martijn Lievaart <>:
    > On Thu, 23 Nov 2006 23:56:42 +0800, sonet wrote:
    >
    > > I have a project must send a lot of file in win2k at the same time.
    > > But what is the best method in win32?
    > > Can the perl build-in function fork work in win32?
    > > Or the perl build-in thread is good solution

    >
    > Besides Anno's answer, be aware that threads have severe limitations. More
    > to the point, threads and signals don't mix. So if you need timeouts (in
    > Perl) or any other signal handling, you are pretty much stuck on forking.
    >
    > Other than that, in general threads are faster than forks. New threads are
    > created faster


    Do you have any evidence for this? While it may be true in general, it
    is very much *not* true of Perl threads as currently implemented. For
    instance, on my machine,

    #!/usr/bin/perl

    use threads;
    use Benchmark qw/cmpthese/;
    use POSIX qw/_exit/;

    cmpthese -5, {
    fork => sub {
    my $p = fork;
    if ($p) {
    waitpid $p, 0;
    }
    else {
    sub {
    return;
    }->();
    _exit 0;
    }
    },
    thread => sub {
    async {
    return;
    }->join;
    },
    };

    __END__

    produces

    Rate thread fork
    thread 47.2/s -- -99%
    fork 4451/s 9326% --

    , so forking is an order of magnitude faster than threading. Perl
    ithreads are basically an implementation of fork(2) in userspace, so
    it's not surprising the OS can do it rather better.

    > and interthread/process communication is generally faster.


    This I would also expect to be false of Perl threads atm, but I can't be
    bothered to devise a benchmark. Of course, if you are passing around
    Perl data structures, it may be much easier to use threads; but even in
    this case, I would advise looking at forks.pm instead.

    Ben

    --
    "If a book is worth reading when you are six, *
    it is worth reading when you are sixty." [C.S.Lewis]
     
    Ben Morrow, Nov 24, 2006
    #4
  5. In article <ek4gc0$82u$>,
    says...
    > I have a project must send a lot of file in win2k at the same time.
    > But what is the best method in win32?
    > Can the perl build-in function fork work in win32?
    > Or the perl build-in thread is good solution
    >


    From what I've seen, fork bugs with script in tainted mode under
    ActivePerl 5.8.[7|8] for Windows. So, I'm used to go through fork unless
    under Windows where I adapt code to go through Win32::process.
     
    Yohan N Leder, Nov 24, 2006
    #5
  6. In article <>,
    says...
    > In article <ek4gc0$82u$>,
    > says...
    > > I have a project must send a lot of file in win2k at the same time.
    > > But what is the best method in win32?
    > > Can the perl build-in function fork work in win32?
    > > Or the perl build-in thread is good solution
    > >

    >
    > From what I've seen, fork bugs with script in tainted mode under
    > ActivePerl 5.8.[7|8] for Windows. So, I'm used to go through fork unless
    > under Windows where I adapt code to go through Win32::process.
    >


    Also, forget to say, "use threads;" falls in the same bug as fork in the
    same case.
     
    Yohan N Leder, Nov 24, 2006
    #6
  7. On Fri, 24 Nov 2006 11:55:19 +0000, Ben Morrow wrote:

    >
    > Quoth Martijn Lievaart <>:
    >> On Thu, 23 Nov 2006 23:56:42 +0800, sonet wrote:
    >>
    >> > I have a project must send a lot of file in win2k at the same time.
    >> > But what is the best method in win32?
    >> > Can the perl build-in function fork work in win32?
    >> > Or the perl build-in thread is good solution

    >>
    >> Besides Anno's answer, be aware that threads have severe limitations. More
    >> to the point, threads and signals don't mix. So if you need timeouts (in
    >> Perl) or any other signal handling, you are pretty much stuck on forking.
    >>
    >> Other than that, in general threads are faster than forks. New threads are
    >> created faster

    >
    > Do you have any evidence for this? While it may be true in general, it
    > is very much *not* true of Perl threads as currently implemented. For
    > instance, on my machine,


    Thanks! I was talking in general, I didn't know Perl threads were this
    slow.

    M4
    --
    Redundancy is a great way to introduce more single points of failure.
     
    Martijn Lievaart, Nov 24, 2006
    #7
  8. sonet

    Guest

    Martijn Lievaart <> wrote:
    > On Thu, 23 Nov 2006 23:56:42 +0800, sonet wrote:
    >
    > > I have a project must send a lot of file in win2k at the same time.
    > > But what is the best method in win32?
    > > Can the perl build-in function fork work in win32?
    > > Or the perl build-in thread is good solution

    >
    > Besides Anno's answer, be aware that threads have severe limitations.
    > More to the point, threads and signals don't mix. So if you need timeouts
    > (in Perl) or any other signal handling, you are pretty much stuck on
    > forking.
    >
    > Other than that, in general threads are faster than forks.


    Maybe in some languages, but in Perl they generally aren't.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Nov 24, 2006
    #8
  9. sonet

    nalhawash Guest

    thks

    Nasser Alhawash

    On Nov 24, 4:08 pm, wrote:
    > Martijn Lievaart <> wrote:
    > > On Thu, 23 Nov 2006 23:56:42 +0800, sonet wrote:

    >
    > > > I have a project must send a lot of file in win2k at the same time.
    > > > But what is the best method in win32?
    > > > Can the perl build-in function fork work in win32?
    > > > Or the perl build-in thread is good solution

    >
    > > Besides Anno's answer, be aware that threads have severe limitations.
    > > More to the point, threads and signals don't mix. So if you need timeouts
    > > (in Perl) or any other signal handling, you are pretty much stuck on
    > > forking.

    >
    > > Other than that, in general threads are faster than forks.Maybe in some languages, but in Perl they generally aren't.

    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > Usenet Newsgroup Service $9.95/Month 30GB
     
    nalhawash, Nov 25, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SBC Global News Server

    How do I choose best locale from a specific list?

    SBC Global News Server, Sep 22, 2003, in forum: Java
    Replies:
    0
    Views:
    384
    SBC Global News Server
    Sep 22, 2003
  2. arieljake
    Replies:
    3
    Views:
    354
    arieljake
    Feb 9, 2005
  3. mtp
    Replies:
    13
    Views:
    789
    Oliver Wong
    Mar 28, 2006
  4. Max2006
    Replies:
    2
    Views:
    422
    Max2006
    Jul 26, 2007
  5. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    602
    Eric Snow
    Jan 8, 2009
Loading...

Share This Page