Multithreading Overview

Learn what threads are and their importance in responsive applications.


Modern applications perform many tasks at the same time. For instance, when we send a photo to our family members with a messenger application, we continue receiving messages while our photo is being uploaded. The method that uploads a photo and the method that receives a message run virtually in a simultaneous manner. Different parts of the system continue to operate at the same time because they run on separate threads. Utilizing several threads is called multithreading.

Note: Threads are unique execution paths with separate control flows. That is, threads don’t affect one another unless they use some common resource, like disk memory.

All code examples we’ve written so far run on a single thread. The subsequent line of code doesn’t run until the previous one finishes executing. In a real-life application, it would look something like this:

  • We click the “Download” button and the download starts. The user interface freezes until the download finishes.

Let’s introduce multithreading to this scenario:

  • We click the “Download” button and the download starts on a background thread. The user interface stays responsive and doesn’t freeze.

Multithread in a multicore environment

Modern computers run on multicore processors, which involves several processors inside a single chip. Each core can handle computations independently. Running several threads on multiple cores would look as follows:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy