[EN] Process, Thread, Asynchrony, Parallel – what is the difference?

This post is a part of preparation for 70-483 exam. Information written down here refers to the part Manage program flow.

First of all I decided to explain the differences between concepts which come along with a phrase multithreading. The meaningful terms are the ones from the title of this article: Process, Thread, Asynchrony, Parallel.

Process

In general process can be treated as a container for the entire application. OS ensures that different processes can’t influence each other and the benefit is that the particular application is isolated from the others. Every process consists of a separate address space, memory, context (state of the processor, registers etc.) and resources allocated by the OS such as CPU, file handles, devices handles, sockets. A single process has at least one thread, but it can hold multiple threads as well.

Thread

Thread is something like the smallest unit of work (sequence of programmed instructions) which is scheduled by the operating system and executed by the CPU. Threads existing in the same process can share memory and resources. The concept of processing the threads is that each thread is allowed to execute for a certain time period. When the time elapses, the thread is paused and OS runs a different one. It is called context switching. Considering Windows as an operating system it can be said that:

In practice, this means that Windows has to do some work to make it happen. The current thread is using a certain area of memory; it uses CPU registers and other state data, and Windows has to make sure that the whole context of the thread is saved and restored on each switch.

Exam Ref 70-483: Programming in C#

When context switching is used threads are executed concurrently but it does not necessarily mean that they are processed in parallel. It happens when threads are executed on the same core. CPU switches context extremely fast and it gives an illusion that they are run in parallel.

Asynchrony

In general asynchrony is a way of parallel processing where operations are run in a nonblocking fashion. When a method needs to call another method that potentially can block, instead of calling that method directly you can use asynchrony to avoid the blocking of the calling method.

Let say that the application executes some long running operation such as accessing data on the disk or transferring the data over the network. In this situation the thread is paused by the system and it has to wait until external processing will finish. The downside is that the application is frozen. Meanwhile the paused thread could be used for a few more things. Asynchrony solves this problem, in simple words it allows the thread to go forward while the external operation is being executed at the same time.

Parallel

Parallel means that two things take place physically at the same time. Asynchrony is one of the examples. On the other hand parallel takes place when two (or more) threads are being executed at the same time on different CPUs or cores.

Summary

I’ve tried my best to describe the terms in a simple and convenient manner. It is an essential background to understand C#/.NET specific things like: async/await, Thread Pool, PLINQ and more. I’m going to provide the technical details in further posts, be patient.

One comment on “[EN] Process, Thread, Asynchrony, Parallel – what is the difference?
  1. Pingback: [EN] Exam 70-483 Programming in C# - Introduction - Tymoteusz Kęstowicz .NET developer blog

Say something

Your email address will not be published. Required fields are marked with a grey bar.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Current ye@r *