Thread

3:11 AM Posted In Edit This 0 Comments »


  • Single-threaded process has one program counter specifying location of next instexecuteO Process executes instructions sequentially, one at a time, until completion
  • Multi-threaded process has one program counter per thread



Benifits of Multithreaded process


User Threads

*Thread management done by user-level threads library

*Three primary thread libraries:

*POSIX Pthreads
*Win32 threads
*Java thread


Kernel Threads

Supported by the Kernel

Examples

Windows XP/2000

Solaris

Linux

Tru64 UNIX

Mac OS


Thread library


The threads library allows concurrent programming in Objective Caml. It provides multiple threads of control (also called lightweight processes) that execute concurrently in the same memory space. Threads communicate by in-place modification of shared data structures, or by sending and receiving data on communication channels



-it is implemented by time-sharing on a single processor. It will not take advantage of multi-processor machines. Using this library will therefore never make programs run faster. However, many programs are easier to write when structured as several communicating processes.


Multithreading Models



The supports for threads can be provided either at the user level, called user threads, or by the kernel, called kernel threads, in which kernel threads are supported and managed directly by the OS. All contemporary OS support kernel threads. „ Ultimately, there must be a relationship between user threads and kernel threads, and there are three common ways of establishing relationships




*Many-to-One








many user threads are mapped into one kernel thread (Fig 4.2 in textbook on page 126, slide 3.45). Thread management is done by the thread library in use space, so this is very efficient; but the entire process will be blocked if one thread makes a blocking system call since only one thread can access the kernel at one time. Also multiple threads are unable to in parallel on multi-processors.







Many user-level threads mapped to single kernel thread

Examples:

Solaris Green Threads

GNU Portable Threads








*One-to-One




each user thread is mapped into one kernel thread. It provides maximum concurrency by allowing another thread to run when a thread (currently running) is blocked; It also allows multiple threads (within a process) to run in parallel on multiprocessors. The drawback is that the creation of a user thread requires the creation of the corresponding kernel thread. There is usually more overhead creating kernel thread than creating user thread, and most implementation of this model restricts the number of threads that can be supported by the system.

Each user-level thread maps to kernel thread

Examples

Windows NT/XP/2000

Linux

Solaris 9 and later








*Many-to-Many Model




this typically allows many user-level threads to be mapped to a smaller or equal number of kernel threads, which is a hybrid model of the first two models. It provides better concurrency than many-to-one model (less than one-to-one model), yet is flexible in that it can create many user-threads not restricted by the number of kernel threads

Allows many user level threads to be mapped to many kernel
threads

Allows the operating system to create a sufficient number of
kernel threads

Solaris prior to version 9

Windows NT/2000 with the
ThreadFiber package
























0 comments: