Subscribe to our RSS Feeds

2 Comments »

What is Thread

A thread is a sequence of instruction within a process. A thread also represents the sequential flow of execution of the task of a process. A process may consist of one of many threads. Therefore a thread is sometimes called a lightweight process. Each thread has its own information of program counter, CPU register and stack. In a process, threads are typically used for dividing a task in a web browser are divided into multiple threads such as,
  • Task to download the images
  • Task to download the text
  • Task to display images and text etc
You have observed that downloading images take more time than text. In this case one thread remains busy for downloading images, while other threads download and display the text. It must be noted that each process occupies an independent address space in memory. But all threads of the process share the same address space. On the basis of process execution, the Operating System can be classified as,
1.      Single-Process single-thread
2.      Single-Process multiple-threads
3.      Multi-Process single-thread
4.      Multi-Process multi-threads
The simplest arrangement is single-process single-thread. Where only one task can be perform at a time. MS DOS is an example of a single-process single-thread operating system. For example in a word processor program only one process can execute at a time. The user cannot simultaneously type text and run the spell checker within the same process.
To day modern systems allow a process to have multiple threads per process. A Java run-time environment is an example of a system of one process with multiple threads.
The multiprogramming system allows the CPU to be shared by multiple processes, for example UNIX supports multiple users’ processes but each process has only one thread.
Some operating system allows multiple process and multiple threads per process like Windows, Linux and OS/2 etc.
User level and kernel level threads
The support for thread may be provided either at user level or by kernel level. Therefore threads may be divided into two categories.
  1. User-level Threads
  2. Kernel-level Threads
User-level Threads
In user level threads all work of threads management is done by the application without kernel support. Any application can be programmed to be multithreaded by using a threads library, which has a collection of routines that can be sued for user level threads management. For example threads library contains the routines for
  • Creating and destroying threads
  • Passing data between threads
  • Scheduling threads
  • Saving and restoring states of threads etc.
Once and application is loaded into user space, all the threads are created and managed within the user space of a process, by default an application begins with a single thread and continuously running in that thread. This application and its thread are managed by the Kernel. At any time the application may create many threads within the same process. A separate data structure for each thread also created. Some scheduling algorithm is also used to pass control to one thread to another within the process; when control is switched from one thread to another that state of the currently executed is saved and then restored which control returns back.
Kernel-level thread
In kernel level thread all work of threads management is done by the kernel of operating system. There is no thread management code in user space of the process. In this approach when control is switched form one thread to another within the same process then control also has to switch form user mode to kernel mode. So this approach affects the performance of the system. Scheduling by the kernel is done on a thread basis. Most of the operating system support kernel threads. These systems are windows XP, Linux and Solaris etc.
Multithreading Models
There must exist a relationship between user threads and kernel threads. These relationships can be established by using the following models.
  1. Many to One model
  2. One to One model
  3. Many to Many model
Many to one model
In many to one model a user space is allocated to single process and multiply threads may be created and executed within that process. The application and its threads are managed by the kernel. The many to one model maps many user level threads to one kernel thread. Thread management is done by the thread library in user space. In this model the entire process will be block if a thread makes a blocking system call. Only one thread can access the kernel at a time so it is impossible to run multiple threads in parallel on multiprocessors system.
One to One model
The one to one model maps each user level thread to one kernel thread. This modl provides more concurrency than many to one model, because it allows another thread to run when a thread makes a blocking system call. This model also allows multiple threads to run in parallel on multiprocessors system.
Many to Many models
The Many to Many models multiplexes many user level threads to smaller equal number of kernel threads. The number of kernel threads may be specific to either a paruvullar application or a particular machine.

 

1:48 PM

2 Responses to " "

online practice tests Says :
April 4, 2011 at 3:54 PM

Many to one model make a sub threads in side the original thread.

Laptop Computers Says :
May 6, 2011 at 2:45 PM

To clear the things up, multithreading is basically the same thing as hyperthreading, as Microsoft calls it.

Post a Comment