YTread Logo
YTread Logo

Multitasking vs Multithreading vs Multiprocessing

Jun 02, 2021

multitasking

,

multiprocessing

and

multithreading

, now there are three interesting words for you all that start with the word multi, well what do they all mean and what is the difference? Well, my name is Gary Sims and this is Gary, explain and if you want to find out. More about those three words, please let me explain. Well, first of all, there may be some overlap in how people use these words and that's okay, but if we're talking about a strict definition, let's look at these three words in order and see what they mean. For us, the first word is

multitasking

and we use it to refer to people, don't you know? once because we don't have a pair of hands but of course it's the same with a computer you have, if it's a single core CPU it can only do one thing at a time, yet it makes it look like it's doing two things at once. and the way it does that is it gives a little bit of time to each of the tasks that it has to do, so if you're running, you know, on your computer, a single core computer and we'll talk more.
multitasking vs multithreading vs multiprocessing
We'll talk about single-core computers in a moment, but if you're running some sort of computer, you might be running something like Microsoft Word and you might also have the Chrome web browser open and a new email arriving in Gmail and even so. You can still continue typing in Microsoft Word, it looks like you are doing two things at once and that is because the computer spends a portion of its time on each program in turn and the programs demand the most CPU usage. longer, so if you have a program that does something really heavy, the other programs seem to be quite slow when you try to click on them or try to use them and the way operating systems do it using a system called pre-free multitasking and that basically means this is the core of the operating system or is it Windows with us Linux with us Mac OS says okay, now you're getting a chunk of time and then it says I don't care what you're doing now I'm going to stop you from what you're doing. doing.
multitasking vs multithreading vs multiprocessing

More Interesting Facts About,

multitasking vs multithreading vs multiprocessing...

I'm giving your time to someone else and that's preventative multitasking. There is a different version called cooperative multitasking if you fancy a full video on multitasking. you know, like cooperative multitasking or preemptive multitasking and something like real time or French ISM, tell me in the comments below and maybe I'll think about making a video on multitasking concepts, but basically the operating system is divided. the time in each program and if you switch between them fast enough it looks like they are both working at the same time now in a little while we are going to go over a couple of raspberry pi's and one of the raspberry pi's that What I will use is a raspberry pi zero and it's a single core version six ARM CPU, which means it can literally only do one thing at a time, it can do one instruction, then the next instruction, the next instruction and we'll see how multitasking plays out. in that when we started running some test programs in that at one point now related to multitasking is

multithreading

now multithreading is what happens when you have parts within the same program within the same task that really want to try to do things in parallel now again we are running this on a single core computer, it can't do things in parallel, it can only do things like the appearance of doing things in parallel, so the scheduler gives one thread a little time and then gives another thread.
multitasking vs multithreading vs multiprocessing
A bit of time and indeed again it looks like the program is accomplishing two things at the same time, so a good example would be, say, something like Android if it ran on a single core, a smartphone like it was ago long time before we had. multicore smartphones, then the GUI, the UI is being updated in one thread and maybe you are downloading from the network with another thread and it looks like the GUI is still interactive and fluid and acts like the downloads happen, but What really What's happening is that the CPU is switching between the two threads, but the point about threads is that they are both inside the same task, they are both inside the same process, therefore they share memory, they share the network, they share files and they all contain. inside that neat little process package that makes it look like the protis itself could do several things at once and again we're going to go to a Raspberry Pi.
multitasking vs multithreading vs multiprocessing
I mean, it will show you a multithreaded program running on a multitasking operating system and then the final variant is

multiprocessing

and multithreading, which means you have more than one CPU core, so nowadays when you are using a pea, you could be using something called symmetric multiprocessing s MP, which basically means a dual core or a quad core or a lot of calls that you have on your processor and in fact those processors can do more than one thing at a time, so you can have a program like Microsoft Word running on a Chrome core and, in fact, physical at the same time.
It could be running on another core and it's actually doing two things at once and that's the difference between when it's running on multi-core and when it's running on single-core. Well, let's go to the Raspberry IPs and see what we can discover. here we are on a raspberry pi 0 it is a single core computer and on the left here we have a window that runs a program called top which shows how much CPU is using which programs and here on the right I have two windows where I can run some programs and let's run a program here where it tries to calculate 250,000 prime numbers using division testing and it does it ten times sequentially one after another, so let's run that and see what happens, look here on the left On the other hand, the program is using 90% of the CPU class and the CPU for the entire system is above 90%.
Okay, it took about eight point eight seconds to run. Now I have another program here that is actually the same thing, but it actually has 10 threads, so instead of running the ten programs sequentially, it actually runs ten threads and tries to calculate all of these prime numbers. Now let's see what happens, again here at the top we can see that the program is using more than 90% of the CPU. The system is 98 96% and you can see here that again it took about the same amount of time, 8.8 seconds, so on a single core machine we have seen how we can run a multi-threaded program and actually Nothing changes. it still takes exactly the same amount of time and there was no speed benefit or performance benefit for it now it's interesting to show us what multitasking is like.
We can run both programs twice, so we'll run it in these two windows. to see if I can get them running as fast as possible, there we go, now let's notice that we have both running and they are both using about 50% of the CPU because they have to share the resources between them, while the system CPU level is in the 90s, it just hit one hundred percent, they're one second, so the overall system is still using the CPU as much as it can and notice it's already done and they both took over 17 seconds. Of course, it was eight point eight seconds for a single run, so if we're running a lot of things, it takes twice as long and the poor old CPU just has to do what it can and this is multitasking because it's trying to run. both programs at the same time and they are both multi-threaded programs so there were 20 threads running there in total and the CPU just ran as fast as it could trying to make it look like it was doing multiple things at once but in reality Of course it wasn't, it was really just dividing the time between each other.
Okay, now let's move on to a Raspberry Pi 3 because here I am on a Raspberry Pi 3 and the Raspberry Pi 3 is different because it has four causes. quad core processor now, first of all, I'm going to run the program exactly the same program that we ran on the Raspberry Pi zero and I want us to see here, it actually runs much faster, it will come out in about 4.1 Seconds, there we go and that It's because the core, the core designs inside the Raspberry Pi 3, they're better, they're faster, those clocks are faster and they're a better design, so actually, which one is faster? do exactly the same program and it was just? running on a core now we are going to run the same program again, but I have increased the number of prime numbers now to a million so that we can have a little more time to talk about what happened, so we run this program now and what we notice here, first of all, that it is running one hundred percent fine on one core again, so the overall system has a load that is clearly 25% because there are four cores and it is running one hundred percent on one core while try to run it? threadless program to calculate those million numbers ten times in a row sequentially in a sequential pattern, so it is maxing out one core and the other three cores are doing nothing and that took about 29 seconds we can see in that time.
Now we can run the threaded version of the same program again using a million numbers to make it a little bit longer and if we press Go the first thing we notice is that it is now almost 400% being used and the reason why is Say 400% it's because it's one hundred percent quad core and now you can see here that this finished much faster four times faster because it finished in 7.5 seconds because it was using all four cores while doing it so it was running a multi threaded program . on a multicore professional Cee'd PU allows the program to run much faster; in fact, we can now do multi-processing and multi-threading by running in both windows.
Here these two programs, run them as fast as we can. Here we go. Now, first of all, notice that we have two running fine and they are using about 200 percent of the CPU time each, which means they are using two cores each, but still the overall system time is still here 100% because all four calls are being used and of course this will take about twice as long because of twice as much work and there we have it 15 point six seconds fifteen point six seconds because the programs were doing it together and that's a example of multiple processing of two running programs.
Multithreading and calls were split up, but as best they could, two calls were maxed out in one program and two calls were maxed out for the other program, so here we go with multiprocessing, multithreading, and multitasking all together and there you have it. my explanation about multitasking, multithreading and multiprocessing. I really hope you enjoyed this video, if you did please like, subscribe and share this video on social media, okay that's it, see you in the next one.

If you have any copyright issue, please Contact