What is a thread?
In a nutshell
A thread is a unit of execution within a process. Multiple threads can run concurrently within the same process.
Each thread has its own program counter, stack, and set of registers. But they share the same memory space and other resources allocated to the process that spawned them. This means that threads within a process can communicate with each other more easily and efficiently than processes can communicate with other processes.
Why use threads?
Parallel processing = responsive UX
You can program an application to do its work in multiple threads so that multiple tasks can be done in parallel. For example, a web browser can use one thread to process user input (e.g., mouse click or text entry) and another thread to make a network request in the background.
By doing each task in a separate thread, the web browser feels responsive.
Resource utilization
Threads are more lightweight than processes. You can spin them up and destroy them more quickly. They can communicate with other threads within a process more quickly and easily. So delegating work to multiple threads utilises your CPU and GPU more efficiently than using processes.
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment