Too many programming terms: Processes and Threads
Hi everyone, today I’d like to explain some very basic principles of computing.
Those are quite interesting for everyone who uses a computer and also important for the continuation of the series.
Okay let’s start scientifically this time and then while we progress I break it down into more understandable pieces:
Definition Process: “A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.” [1]
Definition Thread: “Threads are sometimes called lightweight processes. Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process.” [1]
Now, since that was not as clear let’s use some metaphors.
Okay, let’s take little Fritz and his little sister, Ursula, again.
Fritz’s parents are out for the weekend and left a list of chores for both to do.
Wash the dishes
Clean the floor
Clean the windows
Don’t fight
Clean the bathroom
Tidy up your rooms
Call grandma Berta
We could now describe Fritz and Ursula each as a Processor.
But each of them is only able to do one task at the same time.
The equivalent of this would be a single core processor
The list of chores they have we can easily describe as processes.
That means that each of them is only able to execute one process at a time.
It will be very hard to clean the windows and the floor at the same time, for example.
Now fritz told his sister to clean the bathroom while he will call grandma Berta (To get some more chocolate) which caused his sister to omit chore #4 directly.
Therefore, they had a short constructive discussion and decided to split the tasks up, meaning that each of them will do a part of each of those tasks (Threads).
Since they’re not able to do all the tasks at the same time, they will cut the tasks into little pieces and then switch between the chores after each task.
Or better, they’ll switch between the processes after each thread.
I hope you’re starting to notice the overhead here, the more pieces we cut and the more tasks at the same time, the more time we lose switching those tasks as well.
An example:
Fritz will now:
run down the stairs, clean one plate,
run into the living room brushing 1m² of the floor,
back into the kitchen to clean 1 window
pass his sister without fighting
head into the bathroom and clean the sink
into his room to put one jeans back into the closet
and then run to the phone to send grandma a kiss
This way both guarantee that each one those the same amount of everything, but at the same time they have a huge overhead switching those tasks.
Overhead in italic, actual task in bold (thread).
Therefore, “cleaning a plate” is one of the lightweight sub tasks of the big process “wash the dishes”.
Now, let’s compare that with a real world computer related problem.
The amount of cores your CPU has defines how many tasks he can do literally at the same time (processes).
A single core processor can only execute 1 process at the same time.
You might now ask, how does he then render the interface, open the game, connect with the internet and open the chat at the same time.
He does that exactly like Fritz and Ursula.
In order to do that he iterates through the processes and executes the parts of the process piece for piece.
Inside each process there might be several threads for small subtasks. (Like your web browser which might handle the user interface in one thread and the website loading in another)
While this is quite great, like explained earlier, the more tasks we have, the more processes and threads we might want to spawn, but, the more processes we spawn the more overhead we will have switching between them and we will lose power for this.
Spawning additional threads is also no solution, it's cheaper to switch between them but still, the more we have the more complicated things get.
That’s why the trend diverges to having not only stronger CPUs but also CPUs with more cores.
Stronger CPU = Faster execution per process or thread.
More cores = More processes and threads at the same time.
So one process contains x threads and each thread needs a processor core on its own at the time of its execution.
[1] https://docs.oracle.com/javase/tutorial/essential/concurrency/procthread.html
This gem of a post was discovered by the OCD Team!
Reply to this comment if you accept, and are willing to let us promote your post!
If you accept this, you'll be nominated and the members of the OCD team will vote on whether we'll feature your post in our next compilation post.
You can follow @ocd – learn more about the project and see other Gems! We strive for transparency.
I'm mostly curating in #science and am always glad to see quality posts like yours peeking out between the garbage and plagiarism!
I'd be happy to have you promote me ==)
Congratulations @raycoms! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOPCongratulations @raycoms! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOPSTOP
Notifications have been disabled. Sorry if I bothered you.
To reactivate notifications, drop me a comment with the word
NOTIFY