What is a Process?
A process is a collection of operating-system states that includes file-system handles, graphical windows, network sockets, and at least one thread of execution.
What is a Thread?
A thread is a unit of work that refers to a program image and a memory space.
When an operating system starts a new process, it begins by running a single thread of execution in a program. The program may then decide to create additional execution threads. All the threads, when created, share access to the same set of process states. If a program creates a new process, the threads that run the new process program do not have access to the original program’s process state.
What is deadlock?
Deadlock describes a condition in which two or more threads are blocked (hung) forever because they are waiting for each other. There are many causes of deadlocks. The Thread Analyzer detects deadlocks that are caused by the inappropriate use of mutual exclusion locks.
Analogy:
Think of processes as a pipeline system for your house. A pipeline system will have a water tank( memory, files etc) which will distribute water to your kitchen, bathroom.. etc (threads). Now if some stupid (thread) decides to take an afternoon shower in the bathroom. You will face water scarcity for your kitchen purpose. Hence, creating a deadlock.
For creating a new Process, You would have to buy a new water tank ( allocate memory, etc) and buy a new water motor, which is more costly than adding a new pipeline to a kitchen for the same water tank.
Real-life example:
-
When you are running multiple apps on your Android devices, you have created multiple Processes for each one of them.
-
You can create a multi-threaded server for serving data to multiple clients.
Process ⇒ Multiple Threads ⇒ Locking ⇒ Data is not modified by two threads simultaneously.
References:
-
https://www.reddit.com/r/rust/comments/y0ytw8/process_and_thread/
-
https://docs.oracle.com/cd/E19205-01/820-0619/geokj/index.html#:~:text=Deadlock describes a condition in,use of mutual exclusion locks.