Thursday, July 30, 2009

Single Threaded Process




Multi-Threaded Process
  • Benefits of Multi-threaded Programming
Responsiveness - Parts of a program can continue running even if parts of it are blocked. Book points out that a multi-threaded web browser could still allow user interaction in one thread while downloading a gif in another thread…
*Resource Sharing – pros and cons here. By sharing memory or other resources (files, etc.) the threads share the same address space. (there are issues here…)
*Economy – since threads share resources, it is easier to co
ntext-switch threads than context-switching processes. This should be clear.
*Utilization of MP Architectures – there will be significant increases in performance in a multiprocessor system, where different threads may be runnin
g simultaneously (in parallel) on multiple processors.
*Of course, there’s never ‘a free lunch,’ as we will see later. (There’s always a cost…; nothing this good comes free.
  • User Thread
..Thread management done by user-level threads library
..Three primary thread libraries:
-POSIX Pthreads
-Win32 threads
  • Kernel Thread
*Supported by the Kernel
*Examples

-Windows XP/2000
-Solaris
-Linux
-Tru64 UNIX
-Mac OS X
  • Thread Library
Programmers need help and receive development help via thread libraries germane to specific development APIs..
*A thread library provides an API for creating and managing threads. Java has an extensive API for thread creation and management.
-There are two primary ways to implement thread libraries:
1. Provide thread library entirely in user space – no kern
el support
-All code and data structures for the library exist in user space.
-And, invoking a local function call to the library in user space is NOT a system call, but rather a local function call. (this is good).
2. Implement a kernel-level library supported by the OS.
-Here, code and data structures exist in kernel space.
-Unfortunately, in invoking a function call to the library, there is a system call to the kernel for support.
  • Multi Models

Many-to-one Model

Each user thread maps to one kernel thread
•Is this implementation good (concurrency vs. efficiency)?
–Good concurrency, why? (blocking syscall does not affect other threads)
–Expensive, why? (user-thread creation -> kernel-thread creation)
•How to have both
good concurrency and efficiency?


One-to-one Model

*Each user-level thread maps to kernel thread
*Examples
-Windows NT/XP/2000
-Linux

-Solaris 9 and later


Many-to-Many model

Many user threads are mapped to a smaller or equal number of kernel threads. –Why is this better than Many-to-one? (concurrency & multi-processor) –Why is this better than one-to-one? (efficiency) •Like one-to-one concurrency? –Two-level model.

No comments: