Skip to content
Home ยป Concept of Thread

Concept of Thread

1. Introduction to Threads

A thread is the smallest unit of execution in a process. A process can have one or multiple threads running simultaneously.

๐Ÿ’ก Why use threads?

  • Faster execution (lightweight compared to processes).
  • Efficient CPU utilization (multiple threads share the same process resources).
  • Improves multitasking & responsiveness (e.g., running animations while processing user input).

2. Process vs. Thread

FeatureProcessThread
DefinitionA program in executionA lightweight unit within a process
Resource SharingEach process has separate memory & resourcesThreads share memory & resources of the process
CommunicationInter-Process Communication (IPC) requiredEasier communication (shared memory)
Creation OverheadHigh (new process requires new memory & system resources)Low (threads use existing process memory)
ExampleRunning two different applicationsRunning multiple tasks in a web browser (loading, rendering, scrolling)

โœ” Example:

  • Opening MS Word creates a process.
  • Spell check, saving files, and text formatting run as threads inside the MS Word process.

3. Types of Threads

๐Ÿ“Œ 1. User-Level Threads (ULT)

โœ… Managed by user-space libraries, not the OS.
โœ… Faster context switching since the OS is not involved.
โœ… If one thread blocks, all threads in the process block.

โœ” Example: Java Threads, POSIX Threads (Pthreads)


๐Ÿ“Œ 2. Kernel-Level Threads (KLT)

โœ… Managed by the Operating System (OS).
โœ… Slower than User-Level Threads due to OS involvement.
โœ… Can use multi-core processors efficiently.

โœ” Example: Windows, Linux kernel threads.


4. Multithreading Models

Multithreading models describe how user threads are mapped to kernel threads.

ModelDescriptionExample OS
Many-to-OneMultiple user threads map to one kernel thread.Solaris Green Threads
One-to-OneEach user thread maps to one kernel thread.Windows, Linux
Many-to-ManyMultiple user threads map to multiple kernel threads.Modern Linux, Solaris

5. Benefits of Threads

โœ” Faster Execution โ€“ No need for full process creation.
โœ” Better CPU Utilization โ€“ Multiple threads can run on multiple cores.
โœ” Efficient Memory Use โ€“ Threads share memory, reducing overhead.
โœ” Improved Performance โ€“ Parallel execution speeds up tasks.


6. Example of Threads in Real-Life Applications

โœ” Web Browser (Chrome, Firefox)

  • One thread for UI Rendering
  • One thread for Page Loading
  • One thread for Downloading Files

โœ” Text Editor (MS Word, Google Docs)

  • One thread for Typing Input
  • One thread for Auto-saving
  • One thread for Spell Check

โœ” Video Games

  • One thread for Rendering Graphics
  • One thread for Handling Input
  • One thread for Game Physics

7. Conclusion

โœ” Threads are lightweight execution units inside a process.
โœ” They improve multitasking and CPU efficiency.
โœ” User-Level Threads are faster, Kernel-Level Threads are more powerful.
โœ” Multithreading is widely used in modern software like browsers, games, and OS kernels.