What is threads?
Generally a process consists of number of lightweight process. These lightweight process basically called thread. Actually a threads is a single sequential flow of control within a program. It has a beginning,an end, a sequence etc. But a thread it self is not a program because it cannot run on it's own, it runs with in a program, and thus it makes use of the resources that were actually allocated to the process.
The thread has a program counter that keeps the tracks of which instruction to execute next, it has registers, which hold its current working variables. It has a stack which contains the history of execution. Threads can execute anywhere in the code space of the process.
Uses of threads:
A typical use of threads is found in servee application, such as database server.
Advantage of threads:
3. Threads can also be organised in the pipeline model.
Classification of threads:
There are two ways of thread implementation, they are as follows------
a. User level threads
b. Kernel level threads
a. User level threads:
These type of threads are loaded in the user space only. When Threads are managed in the user space, each process must have its own private thread tables. This pivot table consist of the information of the program counter, stack pointer, register etc, and is managed by runtime system.
By following figure we and demostate the basic concept of user level threads----
The thread has a program counter that keeps the tracks of which instruction to execute next, it has registers, which hold its current working variables. It has a stack which contains the history of execution. Threads can execute anywhere in the code space of the process.
Uses of threads:
A typical use of threads is found in servee application, such as database server.
Advantage of threads:
Or
Basic function of threads:
Threads can perform many of the functions of process --------
1. Threads allows parallelism to combined with sequential execution and block system calls.
2. Threads are frequently used for client.3. Threads can also be organised in the pipeline model.
Classification of threads:
There are two ways of thread implementation, they are as follows------
a. User level threads
b. Kernel level threads
a. User level threads:
These type of threads are loaded in the user space only. When Threads are managed in the user space, each process must have its own private thread tables. This pivot table consist of the information of the program counter, stack pointer, register etc, and is managed by runtime system.
By following figure we and demostate the basic concept of user level threads----
Fig: user level threads
Advantages of user level threads:
1. Each process can have its own scheduling algorithm.
2. User level thread can run on any OS.
3. Faster switching among thread is possible.
Disadvantages of user level threads:
1. When a user level thread execute a system call, not only that thread is blocked but also all of the chat within the process are blocked.
2. Multithreaded application using user level threads cannot take the advantages of multiprocessing sinces kernel assign one process to only one processor at a time.
Kernel level threads:
In this method of thread implementation, the kernel does Total Work of threads movement. There is no thread table in each process. The kernel has a thread table which keeps track of all the threads in a system . The kernel's thread table holds each thread registers, state and other information. Using kernel only, a thread can create a new threads and destroy an existing threads.
By following figure we can demonstrate the basic concept of kernel level thread------
Fig: kernel level threads
Advantages of kernel level threads:
1. It supports multiprocessing also. It means that the kernel can simultaneously scheduling multiple Threads from the same process on multiple processors.
2. Karnal routines them selves can be multithreaded.
3. If a thread within a process is blocked, then the Karnal can schedule another thread of the same process.
Disadvantages of kernel level threads:
1. Switching between thread is time consuming because the kernel mast do the switching.
2. Creation and destruction of the threads in the kernel is costlier.
What is multithreading?
A process is divided into the smaller tasks and the each task is called as a thread. The use of multithreads in a single program, all running at the same time and performing different tasks is called multithreading.
For example, JAVA browser is a multithreaded application.
Advantage of multithreading:
On single processor machines, multithreading have several advantages------
1. Some task take much longer to execute then another.
2. Some task need a better deterministic outcome then other.
3. Some user interface activities is to be run concurrently with hardware communication.
0 Comments
Post a Comment