Saturday, December 17, 2011

Thereds and it's Use

Thereds:-A thread is a single sequential flow of control within a program . or A sequence of a program which runs a certain function within a program.
                          A thread, sometimes called a lightweight process (LWP), is a basic unit of CPU  utilization.
If the process has multiple threads of control, it can do more than  one task at a time.
  ex.-A web browser might have one thread display images or text   while another thread retrieves data from the network.For example, a web server accepts client requests for web pages, images, sound, and so forth. A busy web server may have several (perhaps hundreds) of clients concurrently accessing it. If the web server ran as a traditional single-threaded process, it would be able to service only one client at a time.
    Uses of threads in a single-user multiprocessing system:-
*Foreground and background work:- For example, in a spreadsheet program,
one thread could display menus and read user input, while another thread executes user commands and updates the spreadsheet.It increases speed of the application by allowing the program to prompt for the next command before the previous command is complete.
*Asynchronous processing: -asynchronous elements in the program can be implemented
as threads. For example, as a protection against power failure, one
can design a word processor to write its random access memory (RAM) buffer
to disk once every minute.
*Speed of execution: A multithreaded process can compute one batch of data
while reading the next batch from a device. On a multiprocessor system, multiple threads from the same process may be able to execute simultaneously.
*Modular program structure: -Programs that involve a variety of activities or a variety of sources and  estinations of input and output may be easier to design and implement using threads.
  

No comments:

Post a Comment