Re: threads vs. processes

From: Barry Margolin (barry.margolin_at_level3.com)
Date: 05/03/03


Date: Fri, 02 May 2003 23:29:21 GMT

In article <b8urg8$ran$1@nntp.webmaster.com>,
David Schwartz <davids@webmaster.com> wrote:
> Definitely. User mode threads are, IMO, almost totally useless. The main
>reason people use threads (and this is certainly true in server
>applications!) is to avoid stalling their entire application when they
>block. Why take all the penalties and costs of threads if you don't get the
>primary benefit -- multiple executionn vehicles?!

I always thought that the "main reason" threads were developed is because
it simplifies programming. Rather than writing your own event loop and
maintaining state objects for all your activities, you can just write a
function that handles a single activity and spawn a thread to run it. The
state can be maintained in normal local variables. You can program almost
as if there's just one activity going on; you only have to do anything
special when the threads interact with each other (which is simplified
compared to processes because they share an address space).

Kernel-mode threading is a relatively recent optimization to this. Also a
recent issue is applications which would have so many threads if they
followed the naive model above that they would overload the system. That's
when you have to go to the thread pool model, which necessitates
resurrecting state objects that can be passed to the thread as a parameter;
in this case, you generally need kernel-mode threading because you're
mainly using threads as a fine-grained time-slicing mechanism, not as a
programming abstraction.

-- 
Barry Margolin, barry.margolin@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


Relevant Pages

  • Re: pid_t data type
    ... "The implementation shall support one or more programming environments ... then it *is* save to store pid_t's in a long. ... is a big reason to use pid_t's. ... Because these usually return ints, ...
    (comp.unix.programmer)
  • Re: Delphi in more schools (was Re: Microsoft here I come)
    ... and reading up on programming "stuff" I've sorta figured ... come across is that they stopped reading a long ... If you cannot reason well, I'm not sure doing logic courses ... I hired only one new CS graduate. ...
    (borland.public.delphi.non-technical)
  • Re: Passing Form Objects Via Remoting
    ... you've just posted the first good reason I've ever heard to remote a ... We do XP programming here ... As a general rule in remoting, ... The reason I'm looking into this is ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Check a radio button
    ... Statements about writing code from scratch without using wizards, ... emulate sequential programming in an asynchronous event-based systems, ... He added gratuitous complexity for the wrong reason. ... I've watched products fail because of bad decisions, bad coding practices, ...
    (microsoft.public.vc.mfc)
  • Re: hey, it features a repetition too allied in favour of her exceptional lane
    ... 2600 Magazine (not a secret and not a reason to label someone a criminal). ... The Secret Service is apparently unaware that 2600 magazine is the ... specifically chosen to get around the 900 programming restrictions. ... I remember another one that triggered firm-wide security ...
    (sci.crypt)