Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Operating Systems

Thread Implementation in Operating System



In this article, we are going to learn about thread implementation, its states in Operating Systems.
Submitted by Mahak Jain, on November 07, 2018

Each process has an address space. There is one thread of control in every traditional OS. Sometimes, it is viable to have multiple threads of control in the similar address space which is running in quasi-parallel. Though they were separate processes they have same shared address space.

Threads are used in case of multiple applications running at the same particular time few activities might block from one point of time to another. By decomposition into multiple threads that are running in quasi-parallel, the programming model becomes simpler and easier.

The new element can only be added with threads. This ability to share the same address space and data is essential for some applications.

There are no resources attached to threads. Processes are difficult to create and destroy but threads, on the other hand, can be easily created and destroyed. Creating a thread isabout100x faster than creating a process.

The thread has program counter(pc)to keep the track of the instruction to be executed next. It also has registers to hold the presently working variables. There is a stack to store the execution history there is one frame for one procedure called but not still returned from.

Threads are scheduled for the implementation or execution on CPU.

There are four states of a thread:

  1. Running
  2. Blocked
  3. Read
  4. Terminated

The stack of each thread is as follows:

thread implementation 1

There are two ways of implementing a thread package:

  1. In user space
  2. In kernel

Threads implementation in the user space

In this model of implementation, the threads package entirely in user space, the kernel has no idea about it. A user-level threads package can be executed on an operating system that doesn't support threads and this is the main advantage of this implementation model i.e. Threads package in user space.

Threads implementation in the kernel

In this method of implementation model, the threads package completely in the kernel. There is no need for any runtime system. To maintain the record of all threads in the system a kernel has a thread table.

A call to the kernel is made whenever there is a need to create a new thread or destroy an existing thread. In this, the kernel thread table is updated.

Other two methods are as follows:

  • Hybrid implementation
  • Scheduler activation

Hybrid implementation

In this implementation, there is some set of user-level threads for each kernel level thread that takes turns by using it.

Scheduler activation

The objective of this scheduler activation work is to replicate the working or function of kernel threads, but with higher performance and better flexibility which are usually related to threads packages which are implemented in userspace.

Pop-up threads

In this system, a new thread is created just to handle the message as soon as the arrival of a message takes place and thus it is called pop up thread.

thread implementation 2

The benefit of this pop-up thread is that they are brand new and hence don’t need any stacks or history registers, etc. that must be restored. Each pop-up thread is fresh and new and is similar to all other pop up threads. This is the reason why a pop-up thread can be created very quickly. The incoming message to be processed is given to the new thread.

The result of using such a thread is mainly that the latency between the arrival of the message and the start of processing is made very short.






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.