What are Threads in Operating Systems

What are Threads in Operating Systems

A process is divided into a number of lightweight processes, and each lightweight process is said to be a thread.

The thread has a program counter that keeps track of which instruction to execute next. It has registers, which hold current working variables. It has a stack, which contains the execution history. The number of threads can share an address space, open files, and other resources.

Threads operate in many respects, in the same manner as processes. Threads can be in one of several states: Ready, Blocked, Running, and Terminated. Like the process, threads share the CPU and only one thread at a time is active(Running). Threads can create child threads. Unlike process, threads are not independent of one another because all threads access every address in the task.

A thread can read or write over any other thread stack. Each thread designates a portion of the program that may be executed concurrently with other threads. This capability is called multithreading.

os-threads

The life cycle of thread

A thread is said to be in one of the following several thread states.

  1. Born state: A thread that has just been created.
  2. Ready state: The thread is waiting for the processor (CPU).
  3. Running: The system assigns the processor to the thread (i.e. the thread being executed)
  4. Blocked state: The tread is waiting for an event to occur (or) waiting for an I/O device.
  5. Sleep: A sleeping thread becomes ready after the designated sleep time expires.
  6. Dead: The execution of the thread is finished.
thread_life_cycle

Multi-Threading

A process is divided into a number of smaller tasks; each task is called a thread. A number of threads within a process executed at a time is called multithreading. It is divided into four categories described further.

  1. One Process, One Thread: In this traditional approach, the process maintains only one thread. For example, MS-DOS.
  2. One Process, Multiple Threads: A process divided into a number of threads. For example, Java Runtime Environment.
  3. Multi Processes, One Thread: The operating system supports multiple user processes but only supports one thread process. For example UNIX.
  4. Multi Processes, Multi Threads: In this approach, a process is divided into a number of threads. For example Windows 2000, Solaris, and LINUX.
multithreading

Process vs Threads

ProcessThreads
1. The process can’t share the same memory area (address space)1. Threads can share memory and files.
2. It takes more time to create a process.2. It takes less time to create a thread.
9. It requires fewer resources, so it is also a collected lightweight process.3. Less time to terminate.
4. Execution is very slow.4. Execution is very fast.
5. It takes more time to switch between two processes.5. It takes less time to switch between two threads.
3. It takes more time to complete the executions and terminate them.6. Communication between two threads is very easy to implement. Because threads share the memory.
7. System calls are required to communicate with each other.7. System calls are not required.
8. The process is loosely coupled.8. Threads are tightly coupled.
9. It requires more resources to execute.9. It requires fewer resources, so it is also collected lightweight process.
10. Processes are not suitable for Parallel activities.10. Suitable for parallel activities.

Micro Kernels

A microkernel is a software program, loaded in main memory, to perform some of the functions of the operating system. So the size of the operating system can be reduced.

Microkernel provides process scheduling, memory management, and communication services.

MicroKernel Architecture:

In the Micro kernel architecture essential and main operating system functions should be executed in the kernel mode. Remaining all, means fewer essential services and applications are built on a microkernel and executed in user mode.

Where ordinary operating systems like Layered operating systems, all the essential functions are executed in kernel mode only.

Consider the figure, it shows the architecture of the microkernel.

Benefits of microkernel organization

The main advantages of microkernel organization are:

  • Portability: Portability is the main future of microkernels; microkernels can be suitable for any type of system.
  • Flexibility: The microkernel architecture is flexible.
  • Uniform interfaces: Micro kernel design imposes a uniform interface on requests made by a process.
  • Extensibility: The microkernel architecture can incorporate the new services as well as new hardware devices.
  • Reliability: The size of the software product increases, and the reliability will decrease. Here the microkernel reduces the size of the operating system. So the reliability will increase.

Leave a Comment

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

Scroll to Top