img
. .
What About Shared Memory?
At this time, you may be asking yourself, "What can threads do that can't be done by processes
sharing memory?" The first answer is, "nothing." Most anything that you can do with threads, you
can do with processes sharing memory. Indeed, a number of vendors implement a significant
portion of their threads library in roughly this fashion. There are a few details, such as managing
shared file descriptors, which are not supported on all systems. Nonetheless, the additional
expense and complication of using multiple processes restricts the usefulness of this method. Java
is defined in such a way that sharing memory between processes is not an option, so we will skip
over this technique, which is sometimes interesting to C/C++ programmers.
Threads Standards
There are three different definitions for native thread libraries competing for attention today:
Win32, OS/2, and POSIX. The first two are proprietary and limited to their individual platforms
(Win32 threads run only under NT and Win95, OS/2 threads only on OS/2). The POSIX
specification (IEEE 1003.1c, a.k.a. Pthreads) is intended for all computing platforms, and
implementations are available or in development for almost all major UNIX systems (including
Linux), along with VMS and AS/400--not to mention a freeware library for Win32.
By contrast, Java threads are implemented in the JVM, which in turn is built on top of the native
threads library for the specific platform.[4] Java does not expose the native threads' APIs, only its
own, very small set of functions. This allows Java threads to be easier to use than the native
libraries and more portable, but there are still some significant issues in making programs run
uniformly across all platforms.
[4]
Actually, the JVM is allowed to implement threads any way it feels like. Indeed, the first
implementations of Java used green threads, which were not native. Today, most JVMs are built on
native threads.
POSIX Threads
The POSIX standard defines the API and behavior that all Pthreads libraries must meet. It is part
of the extended portion of POSIX, so it is not a requirement for meeting XPG4, but it is required
for X/Open UNIX 98, and all major UNIX vendors have implemented this standard. In addition,
UNIX98 includes a small set of extensions to Pthreads.
Win32 and OS/2 Threads
Both the NT and OS/2 implementations contain some fairly radical differences from the POSIX
standard--to the degree that even porting from one or the other to POSIX will prove moderately
challenging. Microsoft has not announced any plans to adopt POSIX. There are freeware POSIX
libraries for Win32, and OS/2 also has an optional POSIX library.
DCE Threads
Before POSIX completed work on the standard, it produced a number of drafts that it published
for comment. Draft 4 was used as the basis for the threads library in DCE. It is similar to the final
spec, but it does contain a number of significant differences. Presumably, no one is writing any
new threaded DCE code.
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home