The third model is the strict many-to-many model. Any number of threads are multiplexed onto
some (smaller or equal) number of LWPs. Thread creation is done completely in user space, as are
scheduling and synchronization (well, almost). The number of LWPs may be tuned for the
particular application and machine. Numerous threads can run in parallel on different CPUs, and a
blocking system call need not block the entire process. As in the many-to-one model, the only
limit on the number of threads is the size of virtual memory.[5] No native library actually uses this
strict version, although Sun's implementations of Java 1.1 and 2 do use this.
On a 32-bit machine, this is roughly 2 GB (total virtual memory) / 8 kB (minimum stack size) =
256,000 threads.
The Two-Level Model
The two-level model (known commonly as the many-to-many model) is a strict many-to-many
model with the ability to specifically request a one-to-one binding for individual threads. This
model is probably the best of the choices. Several operating systems now use this model (Digital
UNIX, Solaris, IRIX, HP-UX, AIX). The JVMs on these OSs have the option of using any
combination of bound and unbound threads.
The choice of the threading model is an implementation-level decision for writers of the JVM.
Java itself has no concept of LWPs or threading models. This is a very reasonable choice by the
Java designers; Java programs shouldn't be looking at this kind of low-level detail. Unfortunately,
it brings in a very significant area of possible platform behavior difference.
Win32 Fibers
Win32 has a fibers library, which sits on top of its threads and gives a rough approximation of the
two-level model. However, fibers have a completely different API and require explicit context
switching, so it's best not to consider them to be threads. Indeed, you probably never want to work
with fibers at all.
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks