Threads in Operating System Tutorial Notes Study Material with Examples

Threads in Operating System Tutorial Notes Study Material with Examples

Threads

A thread is a basic unit of CPU utilization. A thread comprises a dimensional program counter , a register set and a stack. It share  with other threads belonging to the same process its code section, data section and other system resources such as open files and signals tradition control, it can perform more than one task at a time.

Multithreading

An application typically is implemented as a separate process with several threads of control. In some situations, a single application may be required. to perform several similar tasks. e.g., a web server accepts client request for web pages, images, sound and so on. A busy web server may have several of clients concurrently accessing it. If the web server run as a traditional single threaded process, it would be able to service only one client at a time.

The amount of time that a client might have to wait for its request to be serviced could be enormous. So, it is efficient to have one process the: contains multiple threads to serve the same purpose.

This approach would multithreaded the web server process, the server would create a separate thread that would listen for client requests, when a request was made rather than creating another process, it would create another thread to service the request.

Multithreading Model

There are two types of threads

(i) User threads                                 (ii) Kernel threads

Kernel Threads

Kernel threads are supported and managed directly by the operating system .

User Threads

They are above the kernel and they are managed without kernel support.

There are three common ways of establishing relationship between threads and kernel threads

(a) Many-to-many model  

(b) One-to-one mode

(c)Many-to-one model

  • One-to-one model maps each user thread to corresponding kernel Threads.
  • Many-to-many model multiplexes many user threads to a smaller or equal ual number of kernel threads,
  • Many-to-one model maps many user threads to single kernel threads.

Key Point

  • User level threads are threads that are visible to the programmer and unknown to the Kernel.
  • User level threads are faster to create and manage than that of Kernel threads.

Process

A process is a program in execution. A process is more than the program code i.e., text section. It also includes the current activity as represented by the value of the program counter and the contents of the processor’s register. Max

Threads in Operating System Tutorial Notes Study Material with Examples
Threads in Operating System Tutorial Notes Study Material with Examples

Process in Memory

Each process is represented in the OS by a Process Control Block (PCB) also called a task control block.

Handbook of CS and IT
Handbook of CS and IT

As processes enter the system, they are put  into a job queue, which consists of all processes in the system.

Handbook of CS and IT
Handbook of CS and IT

The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue.

KeyPoints                                                                                                                                                      ——–

  • The list of processes waiting for a particular I/O device is called a device Each device has it’s own device queue.
  • I/O O bound process is one that spends more of its time doing I/O rather than it spends doing computations.
  • A CPU bound process is one which uses more of its time doing computations rather than it spends doing I/O activities.

Sorting in Design and Analysis of Algorithm Study Notes with Example

Learn Sorting in Handbook Series:  Click here 

Follow Us on Social Platforms to get Updated : twiter,  facebookGoogle Plus

Leave a Reply

Your email address will not be published. Required fields are marked *