in reply to Why use threads over processes, or why use processes over threads?

Let's first address some of your points.

Threads can be created without replicating an entire process. Futhermore, some, if not all, of the work of creating a thread is done in user space rather than kernel space. When processes synchronize, they usually have to issue susyem calls, a relatively expensive operation that involves trapping into the kernel. But threads can synchoronize by simply monitoring a variable - in other words, staying within the user address space of the program.
It's not clear to me what kind of threads you are talking about. See, threads have been invented repeatedly, and in incompatible ways. Many modern operating systems have kernel level threads - that is, the kernel itself is aware of threads, and it may even treat them as processes when it comes to sceduling (but not all OSses do). OTOH, threads can be implemented entirely in a single process, without the OS being aware of it. I think some implementations of Java do it this way.

Now, forking on modern OSses is *cheap*. From the Linux fork() manual page:

Under  Linux,  fork  is  implemented  using  copy-on-write
pages,  so  the  only penalty incurred by fork is the time
and memory required to duplicate the parent's page tables,
and to create a unique task structure for the child.

Now, if we look at how Perl threads are implemented, you'll notice that quite a lot of work needs to be done to start a thread. Far more work then needs to be done than a kernel level fork().

The performance difference is also a winning point for thread over processes. The testing and prove of this itself can be a very big topic, and there are lots of numbers and well accepted testing results, which you can find all over the places.
Could you please post some benchmarking results of Perl threads vs Perl forking? Or post pointers to them?
When some of us are trying to avoiding thread, Perl creators is using threading as a selling point.
They are? I guess that's why ./Configure -des; make creates a threaded Perl. Oh wait, it doesn't.

Here are some reasons why I prefer to use forking over threading:

Abigail

  • Comment on Re: Why use threads over processes, or why use processes over threads?