[PLUG] Re: Multithreading

Elliott Mitchell ehem at m5p.com
Sat Nov 22 17:27:02 UTC 2003


> From: Kevin Theobald <kevintheobald at vzavenue.net>
> Chris Jantzen writes:
>  > Multiprogramming with processes is simpler, safer, and much more
>  > standardized.

I'm skeptical of all three of those. Shared memory space has the crucial
advantages that pointers can be shared, and you don't have to explicitly
share data (you just grab those portions you need from memory rather than
having to ask another process for particular blobs). Certainly with
processes you don't have the subtle memory corruption problems caused by
locking failures, but depending upon the case other just as large
problems are introduced by processes.

Neither is superior in all cases, sometimes processes win, sometimes
threads win.

> With a threading package, such as POSIX Threads (or Pthreads), all the
> threads are in the same process space.  The kernel is not necessary
> for threading to work (though some things may be done there for
> greater speed).  The switching of tasks is done at the user level, by
> the threading library underneath the user code.  This is a big win if
> you happen to have more threads/processors than physical CPUs, because
> switching threads is MUCH faster than switching processes.  (Switching
> processes may require flushing cache(s) in some architectures.)

And a gigantic loss if you've got at least two processors because only
the kernel can schedule threads to execute simultaneously on multiple
processors (or multiple pseudo-processors in the case of a P4).

Try this one on for a subtle (or perhaps not so subtle as time rolls on)
advantage of separate processes. The standard stack is 8MB, quite a bit
larger than typically needed, but reasonable. Think about what happens
when you get 512 threads...

The reason why thread stacks are typically smaller than process stacks.
Intel doesn't have long to bring a 64-bit processor architecture to the
desktop, somehow I doubt ia64 will make it, are they going to produce
amd64 architecture processors? They going to produce a second 64-bit
architecture of their own?


-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \   (    |         EHeM at gremlin.m5p.com PGP 8881EF59         |    )   /
  \_  \   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
    \___\_|_/82 04 A1 3C C7 B1 37 2A*E3 6E 84 DA 97 4C 40 E6\_|_/___/






More information about the PLUG mailing list