Update

One new tab added. Open in browser view if it is not visible. (25/08/2022 08:48)

Threads

To understand threads, one should know about a process.

A process is a program in execution. When that process is segmented further into simpler tasks, those are called threads.

Why does the concept of threads exist?

Reason being, a complete program takes longer to execute. This means for that much amount of time, the memory, the CPU processing, and other resources are taken up by that single process, which in turn delays other tasks which may or may not be time bound.

So when we take a micro-controller or a micro-processor, it is usually single core. Which means parallel execution of processes is not possible.

That's when threads appear. If the processes are sequentially executed, that is a major disadvantage as it may lead to the most critical process being executed much later. So, the processes are broken down further into threads and are then handled by the task scheduler.

Threads are light-weight and easy to create / destroy.

Threads can share data between each other and also memory.

Context - switching is faster in threads as compared to processes.

No comments: