Showing posts with label OS-5. Show all posts
Showing posts with label OS-5. Show all posts

Thursday, July 30, 2009

Multithreading Models

  • Many-to-one

In this model, the library maps all threads to a single lightweight process Advantages: totally portable easy to do with few systems dependencies Disadvantages: cannot take advantage of parallelism may have to block for synchronous I/O there is a clever technique for avoiding it Mainly used in language systems, portable libraries

  • One-to-one

In this model, the library maps each thread to a different lightweight process Advantages: can exploit parallelism, blocking system calls Disadvantages: thread creation involves LWP creation each thread takes up kernel resources limiting the number of total threads Used in LinuxThreads and other systems where LWP creation is not too expensive.

  • Many-to-many

n this model, the library has two kinds of threads: bound and unbound bound threads are mapped each to a single lightweight process unbound threads may be mapped to the same LWP Probably the best of both worlds Used in the Solaris implementation of Pthreads (and several other Unix implementations) .

Thead Library

  • The Thread Library (TL) is a software feature that enables the computer to run programs written to use POSIX Threads fairly efficiently and conscies.

Kernel mode

  • kernel directly supports multiple threads of control in a process

  • Benefits:scheduling/synchronization coordination, less overheadthan process, suitable for parallel application

  • Drawbacks:more expensive than user-level threads, generalityleads to greater overhead

User Thread

  • user libraries implementation

  • Benefits:no kernel modifications, flexible and low cost

  • Drawbacks:thread may block entire process, no parallelism

Benifits of Multi-threaded Programming

Responsiveness

Resource Sharing

Economy

Utilization of MP Architectures

Theard

  • Single-threaded process

- Single threaded process have one path of execution, and multi-threaded programs have two or more paths of execution. Single threaded programs can perform only one task at a time, and have to finish each task in sequence before they can start another. For most programs, one thread of execution is all you need, but sometimes it makes sense to use multiple threads in a program to accomplish multiple simultaneous tasks.

  • Multi-threaded process

Each process can include many threads.

All threads of a process share:

–memory (program code and global data)


–open file/socket descriptors


–signal handlers and signal dispositions


–working environment (current directory, user ID, etc.)