threads (was Re: [gclist] Re: gclist-digest V3 #84)

Bob Kerns Bob.Kerns@brightware.com
Thu, 22 Jun 2000 22:06:41 -0700



-----Original Message-----
From: Andrew Chen [mailto:chenandr@cse.msu.edu]
Sent: Thursday, June 22, 2000 20:42
To: gclist@iecc.com
Subject: %%: threads (was Re: [gclist] Re: gclist-digest V3 #84)

>Unix supports shared memory between two processes, and this is 
>precisely what threads are, only a different amount of memory is 
>shared. Yet processes are considered heavy and threads considered 
>light in Unix and Unix derivatives. Why is this?

Even when two processes share all the same data, at the same addresses, they
are not sharing the address space. You can easily see this, because you can
make a change in one process (e.g. loading a shared library, or creating a
page somewhere deep in malloc, etc.), and it will not be reflected in the
other.

There are a lot of data structures in Unix that are per-process. As you
would expect from the previous paragraph, one of them is the map from
addresses to actual physical pages. Assume for a moment that page maps have
to be stored in non-paged memory, and take up 8 bytes per physical page of
4096 bytes. This would be 8 Mb RAM, for a fully-populated address space.
Now, perhaps the page table will be paged, or less space used via various
compression tricks, but even so, that's up to 8Mb of data ON TOP OF the
overhead per thread (remember, each process also uses at least one thread).

Different systems may vary as to the cost, but I think it's plain that,
compared to a thread, a process is an inherently "heavyweight" construct.