Threads in Programming

Photo by Olliss on Unsplash

Process

  • The process starts with a single thread [Primary Thread] and later can create more Thread from any of its Threads.
  • A process has at least one thread
  • All Threads of a Process have to access its memory and System resources

Threads

  • The smallest unit of execution to which processor allocates time
  • Program Counter: (contains the address of the next instruction to be executed)
  • a Stack
  • Set of registers
  • A unique id
  • However, a thread itself is not a program. It cannot run on its own but runs within a program

Threads VS Process

  • Threads are easier to create than processes since they don’t require a separate address space.
  • Threads are considered lightweight because they use far fewer resources than processes.
  • Processes are typically independent, while threads exist as subsets of a process
  • Processes have separate address spaces, whereas threads share their address space
  • Context switching between threads in the same process is typically faster than context switching between processes.

Thread Life-cycle diagram

  • Ready
  • Running
  • Sleeping
  • Waiting
  • Dead
  • Blocked

In the next article, we will see the coding implementation of Thread in Java

--

--

--

A passionate in Tech https://www.linkedin.com/in/parathantl

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

DevSecOps series №4 — Protecting environment variables in the most well-known C.I. systems

Top 5 Benefits of Coding for Kids

What I decided after trying several programming languages

Day 4 — CS Fundamentals December — About Networking — TCP vs UDP — A Duel

On building failing digital products.

Policy As Code using Conftest for Terraform

How does Micro.blog even work?

“Ok ok, but when will this be delivered?”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parathan Thiyagalingam

Parathan Thiyagalingam

A passionate in Tech https://www.linkedin.com/in/parathantl

More from Medium

Pair Programming

Why you no?! — Iterative Refactoring

Defensive programming

Peer programming, mob programming, solo programming…