Concurrency vs Parallelism in Android?


#1

As I understand Concurrency and Parallelism

Concurrency- Dealing with multiple tasks at the same time.
Concurrency is when two tasks can start, run, and complete in overlapping time periods. It doesn’t necessarily mean they’ll ever both be running at the same instant. Eg. multitasking on a single-core machine

Parallelism- Actually executing multiple task at the same time.
Parallelism is when tasks literally run at the same time, eg. on a multicore processor.

As we know that every Android App runs in its own process and allocates some memory.As in a multithreaded app, multiple threads are running simultaneously.Does those multiple threads are running concurrently or parallely? I can assume that if the Android Device is Single Core then the multiple threads are running Concurrently. But what if the Android Device has multiple cores(e.g dual core, quad core etc), are they all running parallelly here ?

Because all those threads are running in a single process, they will use the process address space for execution.So the question is does on a multi-core android device all the threads runs parallel?


#2

My apologies for responding later than I would have liked…

As I understand Concurrency and Parallelism

I have never seen those definitions prior to your post. I would define concurrency as “dealing with the problems created by parallel operations”.

Does those multiple threads are running concurrently or parallely?

That will depend entirely on your definition of “concurrently” and “parallelly”. I would say that both threads are running concurrently and in parallel, as to me “concurrently” and “in parallel” mean the same thing.

So the question is does on a multi-core android device all the threads runs parallel?

That is up to the device manufacturer, the kernel implementation, the CPU capabilities, the number of threads, and other environmental things (e.g., whether your app is in the foreground). For example:

  • If you fork 3,141,598 threads, since you probably are not on a machine with that many cores, only a subset of the threads will be executing at any point in time

  • Even if you have fewer threads than cores, not all cores might be used at once (e.g., big.LITTLE architectures where either the big cores or the little cores are used, but not both)

  • Even if you have fewer threads than active cores, the scheduler might run unblocked threads from other processes from time to time

  • And so on


#3

@mmurphy

I don’t agree that concurrency is same as Parallelism .
Concurrently is nothing but an illusion of Parallelism.Things don’t run parallely when they are concurrent.It just seem that they are running at the same time.The Cpu is switching between multiple tasks at a very high speed.Because of the speed it seems parallel.Like running multiple photos at a higher speed gives us illusion of animation.
See this video - Concurrency Is Not Parallelism


#4

Thanks for this explanation!