Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Introduction To Thread In Linux (Part 14/24)

By Ashish Vara

Thread In Linux

In this tutorial, I will explain about thread which is an important topic in Linux. You  must have heard about in multithreading in Linux. I will explain what the thread is and how it works. Let’s take the same example which I explained in tutorial Process in Linux.

thread in linux

Fig. 1: Image showing Threads in Linux

If I want to make my passport but I don’t know what  the process is, I will go to the inquiry window and ask about it. Process is nothing but carrying out a task. My task is to make passport and process is how to make passport. Now you must be wondering as to where the thread is. The process of making a password is more typical and time consuming if only one member or officer is working on it. In other words if the verification of documents in a passport office is handled by only one member, it will take more time because he or she will verify the documents of users in a sequential approach. However if there are more than one member, then it will take less time because user has divided per member in parallel approach. Handling of user per member is nothing but same as thread. So, simply thread is part of process which works along with process.

Thread is similar to process. We can say that it is a light weight processwhich shares the same address space, data and attribute of process. It is single sequence stream within a process similar to a mathematical or some small function of code which  runs within process. Before learning about thread, you should know about Process. You can refer to the Process in Linux tutorial.

 

Linux-processes-life-cycle

Fig. 2: Image showing Life Cycle of Linux Processes

Processes are used to group resources together and heavy weight task. Threads are entities scheduled for execution on CPU. It is a popular way to improve application through parallel approach. CPU switches back and forth between threads rapidly so as to switch of the thread working in parallel. Each thread has its own stack, PC and several registers. These share their data with another thread within the same process and are not independent like a process.

 

Process Vs Thread

Process vs Thread

Fig. 3: Image showing Prcesses in Context to Threads

Thread is similar but somehow different to a process. Similarity between process and thread are following:

  • Like process, thread shares CPU
  • Only one thread is active at a time same as process.
  • Thread can also create children like process.
  • One thread is blocked when another thread  runs like process.

Difference between process and thread are  as follows:

  • Threads are not independent unlike process
  • Thread can access only address in task

 

Need of Thread

We already know that process and thread are mostly similar. So, why do we use thread in application? Process with multithread is very useful in great server. Switching between processes is slower than thread. Thread uses very light weight resource and context switching fast. It can share common data without the need of IPC. Two or more threads are communicated to each other without pipe or FIFO. Multithreading technique is helpful to develop effective application.

Types of Thread

  1. User Thread
  2. Kernel Thread

1. User Level Thread

User thread works at user level. It has no need of system call and hence does not need to call OS. User thread is managed by application and thread library. Kernel does not know anything about user thread. User thread has following advantages:

  • No need to modify OS.
  • Each thread is represented by small control block, stack, PC, register and all are stored in same process address space.
  • Creating, switching, synchronization of thread is simple without intervention of kernel. User thread is not much  expensive.

User thread also has following disadvantages:

  • Lack of coordination between user thread and kernel
  • It does not provide the protection of thread

2. Kernel Thread

It manages thread and s also schedules it. Kernel threads have thread table which keeps track of all thread in system same as process. It has full knowledge of thread but at the same time it is very slow and inefficient. It increases the kernel’s complexity and requires full thread control block.


Filed Under: Tutorials

 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Timer MC14541B wrong delay
  • Pull up via GPIO
  • Electrical Lenght of Microstrip Transmission Lines
  • How to Draw/Display a BMP or PNG on 3.2" TFT Display with inbuilt ILI9341 IC
  • file edit

RSS Electro-Tech-Online.com Discussions

  • DIY bluetooth speaker
  • Turn CD4029 on/off with TTP223
  • Need a ducted soldering fan for solder smoke extraction
  • Question about ultrasonic mist maker
  • Power failure relay options
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering