THOUSANDS OF FREE BLOGGER TEMPLATES

Thursday, July 30, 2009

Thread

  • A thread (or lightweight process) is a basic unit of CPU utilization; it consists of:
o Thread ID
o program counter
o register set
o stack space
  • A thread shares with its peer threads its:
o code section
o data section
o operating-system resources
  • A traditional or heavyweight process has a single thread of control.
  • In a multiple threaded task, while one server thread is blocked and waiting, a
second thread in the same task can run.
o Cooperation of multiple threads in same job confers higher throughput
and improved performance.
o Applications that require sharing a common buffer (i.e., producer-
consumer) benefit from thread utilization.
  • Threads provide a mechanism that allows sequential processes to make
blocking system calls while also achieving parallelism.

Single Threaded Process




Multi-Threaded Process

Benefits of Multi Threaded Programming
  • Responsiveness
  • Resource Sharing
  • Economy
  • Utilization of MP Architectures


User Thread
  • Thread management done by user-level threads library
  • Fast to create and manage threads
  • If the kernel is single-threaded, then any user-level thread per
blocking system call will cause the entire process to block
  • Examples
- POSIX Pthreads
- Mach C-threads
- Solaris UI-threads

Kernel Thread
  • Supported by the Kernel
  • Slower to create and manage threads than are user threads
  • If a thread performs a blocking system call, then the kernel can schedule
another thread in the application for execution.
  • Multiple threads are able to run in parallel on multiprocessors.
  • Examples
- Windows NT/2000
- Solaris 2
- Tru64 UNIX
- BeOS
- Linux

Thread Library
  • A thread library provides the programmer with an API for creating and managing threads
  • Three main libraries:

-POSIX Pthreads

-Win32

-Java


Multithreading Models
  • Many-to-One Model
  • One-to-One Model
  • Many-to-Many Model


Many-to-One Model

  • Many user-level threads mapped to single kernel thread
  • Used on systems that do not support kernel threads.
  • Allows many user level threads to be mapped to many kernel thread
  • Allows the operating system to create a sufficient number of kernel threads
  • Solaris prior to version 9
  • Windows NT/2000 with the ThreadFiber package



Slide 17
n


One-to-One Model
  • Each user-level thread maps to kernel thread.
  • Creating a user thread requires creating the corresponding kernel thread.
  • Windows NT/2000, OS/2
  • Each user-level thread maps to kernel thread
  • Examples

    -Windows NT/XP/2000

    -Linux

    -Solaris 9 and later




Slide 5

0 comments: