All this talk about concurrency and parallelism tends to confuse an average developer.Specially one who considers himself pretty capable in threading , at this point however he begins to have doubts about his skills and eventually begins to entertain the fact that he might be getting outdated.Well no worries the aim of this post is to calm those developers down and to explain what the above jargon really means or at least my point of view.Now both the terms concurrency and parallelism basically refer to the the behavior of a multi threaded application.
What is concurrency ?
Before defining concurrency we need to know how an operating system handles threads.In
Windows a thread is given about (3 Quantums or 10 milliseconds) of a processors time.
Now if the processor under discussion is a single processor and our multithreaded application has 2 threads then theoretically speaking each thread will be given about 10 milliseconds to work after which the CPU will shift its attention over to the other thread thus temporarily pausing the previous thread.(Practically Windows basically allows you to configure priority of background threads but that's another topic) When talking about concurrent applications we only compare the threads of that application . More details can be found here
Anyways as we already mentioned that the previous thread would be stopped and a new thread would be started.Since 10 milliseconds is a very very small interval it appears to us as if the two threads are running simultaneously.Now we know that is untrue.This behaviour is known as concurrency in which threads of an application are run by a processor one by one after intervals.
What is parallelism ?
Now suppose we are using windows in a multiprocessor environment now each thread in the multi threaded application can run on a separate processor, resulting in parallel execution, which is true simultaneous execution , thus called parallelism . When the number of threads in a process is less than or equal to the number of processors available, the operating system's thread support system ensures that each thread runs on a different processor.This is know as parallelism
What is concurrency ?
Before defining concurrency we need to know how an operating system handles threads.In
Windows a thread is given about (3 Quantums or 10 milliseconds) of a processors time.
Now if the processor under discussion is a single processor and our multithreaded application has 2 threads then theoretically speaking each thread will be given about 10 milliseconds to work after which the CPU will shift its attention over to the other thread thus temporarily pausing the previous thread.(Practically Windows basically allows you to configure priority of background threads but that's another topic) When talking about concurrent applications we only compare the threads of that application . More details can be found here
Anyways as we already mentioned that the previous thread would be stopped and a new thread would be started.Since 10 milliseconds is a very very small interval it appears to us as if the two threads are running simultaneously.Now we know that is untrue.This behaviour is known as concurrency in which threads of an application are run by a processor one by one after intervals.
What is parallelism ?
Now suppose we are using windows in a multiprocessor environment now each thread in the multi threaded application can run on a separate processor, resulting in parallel execution, which is true simultaneous execution , thus called parallelism . When the number of threads in a process is less than or equal to the number of processors available, the operating system's thread support system ensures that each thread runs on a different processor.This is know as parallelism