deadkarma has asked for the wisdom of the Perl Monks concerning the following question:

I remember once compiling a version of perl on Win32(I think it was 5.005) enabling the use of "Threads", which made me ecstatic! It worked well for me, plus using Tk enabled me to make some pretty nifty applications. I also had used perl2exe to make a nice little bundle of joy. Now, having been out of the perl loop for a while, I see Threads being phased out, and scoffed at. Why for? I like threads a lot better than fork. What ever happened? hmph.

Replies are listed 'Best First'.
Re: Thread vs. Fork
by Corion (Patriarch) on Feb 16, 2001 at 22:20 UTC

    Threads would be a nice thing to have, if they worked. The problem is, that threads are not stable, even many operating systems (mostly those that already have fork()) have problems with and different implementations of threads. So it all boils down to another good idea that has yet to see the light for general use.

Re: Thread vs. Fork
by rpc (Monk) on Feb 16, 2001 at 22:58 UTC
    Threads aren't necessarily being phased out, and certainly aren't being scoffed at. They will be an integral part of Perl6. Threads and fork() are significantly different technologies. perl5 didn't begin as a multithreaded interpreter, and I think the fact it supports threading at all is amazing.

    --rpc
      If perl6 has multi-threads as standard, that would be so great. I'm really amazed at how far the language has come.
      I've never used fork(), and even after reading documentation, I don't really understand how it works and how it's different that using system() or backticks.
        Here are some quick answers for you. For more indepth info just do a search of this site:
        • system, stripped down of security features, is simply a fork() and exec(). fork() creates a new process space which exec() populates with whatever process you specified in the shell call.
        • Backticks fire off the shell call in a separate process, then captures STDOUT from it.
        • Threads have far less overhead than a process and are contained within the process which allows concurrent handling of instructions.
        • You may fork() and specify further perl code instead of an exec so that you end up with multiple perl interpreters running in separate process spaces.
        • At any time, you can call exec() which then "overwrites" the process space with a new binary with some exceptions like file descriptors. This is useful to redirect streams before handing over the streams to some process.

        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
        There is a reasonable discussion of how threading and fork differ technically and philosophically at Threads vs Forking (Java vs Perl). In that discussion KM came out with Mr. Peabody Explains fork() which is a very good starting place if you just want to understand what fork is and why it was invented. (In fact I recommend reading it before my link.)
Re: Thread vs. Fork
by manish041083 (Initiate) on Jan 20, 2010 at 20:53 UTC
    Found this. Thought could be useful in the discussion. http://www.geekride.com/index.php/2010/01/fork-forking-vs-thread-threading-linux-kernel/