What is the difference between concurrency and parallelism?
Examples are appreciated.
Parallelism is simultaneous execution of processes on a multiple cores per CPU
or multiple CPUs (on a single motherboard)
.
Concurrency is when Parallelism is achieved on a single core/CPU
by using scheduling algorithms that divides the CPU’s time (time-slice). Processes are interleaved.
Units:
- 1 or many cores in a single CPU (pretty much all modern day processors)
- 1 or many CPUs on a motherboard (think old school servers)
- 1 application is 1 program (think Chrome browser)
- 1 program can have 1 or many processes (think each Chrome browser tab is a process)
- 1 process can have 1 or many threads from 1 program (Chrome tab playing Youtube video in 1 thread, another thread spawned for comments section, another for users login info)
- Thus, 1 program can have 1 or many threads of execution
- 1 process is
thread(s)+allocated memory resources by OS
(heap, registers, stack, class memory)