Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: wnl@groupsys.com (William LeFebvre)
Subject: Re: Understanding threads in Unix
Date: 1998/09/28	[thread overview]
Message-ID: <6umuaf$aeu$1@paxfeed.eni.net> (raw)
In-Reply-To: 360F04C1.ECAD5E9@iname.com

In article <360F04C1.ECAD5E9@iname.com>, lo tek  <lotek@iname.com> wrote:
>>From what I understand on NT, a new thread is different from a new
>process in that a new thread gets its own stack but not its own heap.

What's a heap?  :-)

In Unix, multiple threads execute in the same virtual memory space.
They each have their own execution context (registers including PC
and stack pointer) but they all share the same virtual memory space.
Processes have separate memory spaces as well as execution contexts.

>This means it's faster to initialize a new thread instead of a new
>process.

That's correct (in general).  It also takes fewer resources.

>The advantage is that, for example, a web server only uses new
>threads to handle each request, instead of "blocking" requests and using
>new processes.

Well, the request wouldn't explicitly block.  Instead it would have to
wait as a new process was created, or as the request was dispatched to
a waiting process (which may then have to be paged in).

>How do AIX and Solaris compare in this regard? If neither has threads,
>or neither has many apps that use threads, is this a performance
>problem? Certainly I'm not suggesting NT would outperform. :) If both
>have threads, which is more stable? Also, if an OS doesn't have threads,
>an app may wish to emulate a threaded
>environment, forcing each vendor to recreate threading which is probably
>not trivial, and therefore error-prone.

Okay, there's threads and there's kernel entities.  A thread is a
virtual object, but a kernel entity is a specific OS's mechanism
for implementing multiple contexts in a single process.  In Solaris
these are called lightweight processes.  You *must* treat these
two items separately.

It is true that threads can be implemented with any sort of API.
There is a POSIX standard threads api called "pthreads" and it is very
widely deployed across many Unix variants.  Before pthreads, some
vendors did implement their own threads mechanism, and it was quickly
headed to the chaotic world you evisioned.  But everyone now is moving
towards pthreads.  This is a good thing.

How a pthreads thread is mapped on to a kernel entity is completely up
to the OS.  Those systems which have no support for kernel-based
threading have no choice but to implement threads in a software
library.  They can do this and still retain the pthreads semantics.
Those systems which have the ability may choose to map threads to
kernel entities one-to-one.  But the better systems implement 2-level
or many-to-few: threads are bound to and unbound from kernel entities
as needed.  This is conceptually similar to how virtual pages are
mapped to physical pages.  One kernel entity (LWP) may handle s
variety of threads throughout its lifetime.

For more info, read my Performance Computing column on Threaded
Programming.  It was published in the September 1998 edition.  Visit:
http://www.performancecomputing.com/columns/daemons/9809.shtml

Better yet, get Butenhof's book.

-- 
				William LeFebvre
				Group sys Consulting
				<wnl@groupsys.com>
				+1 770 813 3224



  parent reply	other threads:[~1998-09-28  4:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-27  4:00 Understanding threads in Unix lo tek
1998-09-28  4:00 ` Ben Elliston
1998-09-29  4:00   ` Patrick TJ McPhee
1998-09-28  4:00 ` William LeFebvre [this message]
1998-09-30  4:00   ` Mark
1998-10-01  4:00 ` Jason Rosenberg
1998-10-02  4:00   ` Mark & Suzanne (gcs might work)
1998-10-01  4:00     ` Chad Schrock
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox