Das Video kommt von YouTube: erst beim Abspielen verbindet sich die Seite mit YouTube (Google).
Concurrency vs Parallelism
Das Wichtigste aus dem Video
Tipp auf eine Zeit – das Video springt genau dorthin.
Transkriptautomatisch erstellt · 65 Zeilen
- the terms concurrency and parallelism are often used when talking about concurrent computing and parallel computing
- on the surface it may seem as if concurrency and parallelism are referring to similar concepts or the same concept
- but they're actually referring to slightly different concepts more specifically we will have a look at concurrency parallel execution
- parallel concurrent execution and parallelism concurrency means that an application is making progress
- on more than one task seemingly at the same time however since a cpu can only execute one program at a time
- the cpu cannot actually execute more than one task at the exact same time instead what the cpu does
- is that it executes one task for a little bit then switches to another task executes that for a little bit
- switches back to the first task here executes that for a little bit switches again and so on and so forth and these tasks are typically called
- threats the switching between their tasks the threats here
- happens so fast that you will not notice it as a user and therefore it seems like the computer is making progress on more
- than one task concurrently at the same time concurrently even though in reality it switches so
- fast that you cannot see the difference the switches from executing on one thread to executing on another
- is also called a context switch and that basically means that the cpu or the operating system is switching context
- from one thread one task to another thread another task parallel execution on the other hand means making progress on more than one
- task or a thread at the exact same time so imagine you have a computer with two cpus then each cpu is capable of executing
- a single thread a single task and continue to execute that single thread all the time it does not have to switch to the other thread here so we can have
- one thread running on each of the cpus and each of these threads can take up the full amount of cpu time on that cpu of course in practice that is not
- possible because the operating system is also consuming some of that cpu time for its own purposes
- but this is the basic principle so these two threads here will be executing in parallel because they are executing on different
- cpus parallel concurrent execution means making progress on more than one task
- seemingly at the same time on more than one cpu so in parallel right so basically what it means is that you have multiple
- threads running on the same cpu here and you have multiple cpus in the computer in the application
- where this is the case so in the example illustrated here we have an application that has four threads running and two threads are running on
- the first cpu and two threads are running on the second cpu so the first two threads here they are running concurrently with respect to
- each other thread two and thread one cannot run at the same time either threat 1 runs or through 2 runs
- the same is true of threat 3 and threat 4 either thread 3 runs or threat 4 runs however whatever threat is running on
- this second cpu here can run completely in parallel with whatever thread is running up here on the first cpu so thread one
- can run in complete parallel with either thread three or four and thread two can run completely in parallel with either
- thread 3 or 4. parallel concurrent execution is actually very similar to concurrent execution
- with the only difference being that there are more cpus on which concurrent execution takes place so that everything that happens on each
- cpu is happening in parallel with whatever happens on the other cpus
- parallelism means splitting a single task into subtasks which can be executed in parallel if you look at the example here
- below we have a big task which is split into four subtasks the splitting of the task happens here
- on the first cpu and then you can see each of these subtasks here are executed by each their own
- thread the first two threads here execute on the first cpu and the second actually the third and the fourth thread
- here are executed on the second cpu and that means that these two subtasks here will actually
- execute concurrently not in parallel and these two subtasks will also only be executing concurrently not in parallel however
- these subtasks here like the subtasks down here can execute in parallel with the subtasks up here when subtask 3 is executing it
- doesn't really matter which of subtask 2 or subtask 1 that is currently being executed on the first cpu
- naturally it may not always make sense to split a big task into more subtasks than you have cpus
- so in this case here we split the task up into four sub-tasks however since there are only two cpus available
- some of these sub-tasks end up being executed concurrently and not in parallel
- you might as well have just split this task into two subtasks so that subtask 1 was executed on cpu 1 and subtask 2 was
- executed on cpu 2. however even if you know that the computer that the application is running
- on has a certain amount of cpus for instance if you know it has 8 cpus well not all of these 8 cpus may be
- available when your task here is being executed some of the cpus might be busy executing tasks or threats from other applications
- therefore it makes more sense to break a task into sub-tasks based on what parts of the full task that can be executed
- independently for instance if the total task consists of processing four files then the processing of each file can be split
- into its own subtask each subtask can then be executed by its own thread and then you leave it up to the operating system to allocate threats to
- the idle cpus depending on what cpus are currently available applications do not have to use either concurrency
- or parallelism it is possible for applications to combine these two concepts so it's possible for an application to be concurrent but
- not parallel to be parallel but not concurrent should be both concurrent and parallel and to be
- neither concurrent nor parallel an example of an application that is concurrent but not parallel could be an
- application that executes multiple tasks in multiple threads but all the threads are executed on the same cpu
- so we have concurrently executing tasks or threads but not truly in parallel we could also have an application that
- executes one task at a time but breaks that task into subtasks that application would be using
- parallelism but not concurrency because we are only making progress on a single big task at a time even though we break that task into
- subtasks which are then executed in true parallel we can also have an application that is both concurrent and parallel and that
- would be an application that maybe executes multiple big tasks at the same time which and where these tasks are broken into
- subtasks and it is possible for an application to be neither concurrent nor parallel for instance a command line application
- that has to do such a little job that it does not make sense to start up multiple threads or break the task
- into subtasks which are executed in parallel that's all for this video about concurrency versus parallelism
- remember to check out the description below the video for a link to a textual version of this tutorial as well as links to other related
- tutorials if you like this video please hit the like button and if you want to see more videos like this
- subscribe to my channel
Zum Nachlesen
MultithreadingMultithreading (englisch wörtlich für Mehrfädigkeit oder auch Mehrsträngigkeit und, weiter übertragen, die Nebenläufigkeit) bezeichnet in der Informatik das …
Parallele ProgrammierungEs umfasst zum einen Methoden, ein Computerprogramm in einzelne Teilstücke aufzuteilen, die nebenläufig ausgeführt werden können, zum anderen Methoden, …
NebenläufigkeitDie Nebenläufigkeit, mitunter auch Parallelität (englisch concurrency) genannt, ist in der Informatik die Eigenschaft eines Systems, mehrere Aufgaben, …
MultitaskingDer Begriff Multitasking [ˌmʌltiˈtɑːskɪŋ] (engl.) bzw. Mehrprozessbetrieb bezeichnet die Fähigkeit eines Betriebssystems, mehrere Aufgaben (Tasks) …