Zum Inhalt springen
L

Das Video kommt von YouTube: erst beim Abspielen verbindet sich die Seite mit YouTube (Google).

Concurrency vs Parallelism

Jakob Jenkov9:29 82.281 Aufrufe veröffentlicht Auf YouTube

Das Wichtigste aus dem Video

Tipp auf eine Zeit – das Video springt genau dorthin.

Transkriptautomatisch erstellt · 65 Zeilen
Herunterladen
  1. the terms concurrency and parallelism are often used when talking about concurrent computing and parallel computing
  2. on the surface it may seem as if concurrency and parallelism are referring to similar concepts or the same concept
  3. but they're actually referring to slightly different concepts more specifically we will have a look at concurrency parallel execution
  4. parallel concurrent execution and parallelism concurrency means that an application is making progress
  5. on more than one task seemingly at the same time however since a cpu can only execute one program at a time
  6. the cpu cannot actually execute more than one task at the exact same time instead what the cpu does
  7. is that it executes one task for a little bit then switches to another task executes that for a little bit
  8. 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
  9. threats the switching between their tasks the threats here
  10. happens so fast that you will not notice it as a user and therefore it seems like the computer is making progress on more
  11. than one task concurrently at the same time concurrently even though in reality it switches so
  12. fast that you cannot see the difference the switches from executing on one thread to executing on another
  13. is also called a context switch and that basically means that the cpu or the operating system is switching context
  14. from one thread one task to another thread another task parallel execution on the other hand means making progress on more than one
  15. 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
  16. 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
  17. 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
  18. possible because the operating system is also consuming some of that cpu time for its own purposes
  19. but this is the basic principle so these two threads here will be executing in parallel because they are executing on different
  20. cpus parallel concurrent execution means making progress on more than one task
  21. seemingly at the same time on more than one cpu so in parallel right so basically what it means is that you have multiple
  22. threads running on the same cpu here and you have multiple cpus in the computer in the application
  23. 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
  24. 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
  25. each other thread two and thread one cannot run at the same time either threat 1 runs or through 2 runs
  26. the same is true of threat 3 and threat 4 either thread 3 runs or threat 4 runs however whatever threat is running on
  27. this second cpu here can run completely in parallel with whatever thread is running up here on the first cpu so thread one
  28. can run in complete parallel with either thread three or four and thread two can run completely in parallel with either
  29. thread 3 or 4. parallel concurrent execution is actually very similar to concurrent execution
  30. with the only difference being that there are more cpus on which concurrent execution takes place so that everything that happens on each
  31. cpu is happening in parallel with whatever happens on the other cpus
  32. parallelism means splitting a single task into subtasks which can be executed in parallel if you look at the example here
  33. below we have a big task which is split into four subtasks the splitting of the task happens here
  34. on the first cpu and then you can see each of these subtasks here are executed by each their own
  35. thread the first two threads here execute on the first cpu and the second actually the third and the fourth thread
  36. here are executed on the second cpu and that means that these two subtasks here will actually
  37. execute concurrently not in parallel and these two subtasks will also only be executing concurrently not in parallel however
  38. these subtasks here like the subtasks down here can execute in parallel with the subtasks up here when subtask 3 is executing it
  39. doesn't really matter which of subtask 2 or subtask 1 that is currently being executed on the first cpu
  40. naturally it may not always make sense to split a big task into more subtasks than you have cpus
  41. so in this case here we split the task up into four sub-tasks however since there are only two cpus available
  42. some of these sub-tasks end up being executed concurrently and not in parallel
  43. 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
  44. executed on cpu 2. however even if you know that the computer that the application is running
  45. 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
  46. available when your task here is being executed some of the cpus might be busy executing tasks or threats from other applications
  47. therefore it makes more sense to break a task into sub-tasks based on what parts of the full task that can be executed
  48. independently for instance if the total task consists of processing four files then the processing of each file can be split
  49. 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
  50. the idle cpus depending on what cpus are currently available applications do not have to use either concurrency
  51. or parallelism it is possible for applications to combine these two concepts so it's possible for an application to be concurrent but
  52. not parallel to be parallel but not concurrent should be both concurrent and parallel and to be
  53. neither concurrent nor parallel an example of an application that is concurrent but not parallel could be an
  54. application that executes multiple tasks in multiple threads but all the threads are executed on the same cpu
  55. so we have concurrently executing tasks or threads but not truly in parallel we could also have an application that
  56. executes one task at a time but breaks that task into subtasks that application would be using
  57. 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
  58. subtasks which are then executed in true parallel we can also have an application that is both concurrent and parallel and that
  59. would be an application that maybe executes multiple big tasks at the same time which and where these tasks are broken into
  60. subtasks and it is possible for an application to be neither concurrent nor parallel for instance a command line application
  61. that has to do such a little job that it does not make sense to start up multiple threads or break the task
  62. into subtasks which are executed in parallel that's all for this video about concurrency versus parallelism
  63. 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
  64. tutorials if you like this video please hit the like button and if you want to see more videos like this
  65. subscribe to my channel

Zum Nachlesen