Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 1.27 KB

threads-motivation.md

File metadata and controls

37 lines (24 loc) · 1.27 KB

Motivation - Why do we need Threads?

For two primary things:

  1. Responsiveness
  2. Performance

Responsiveness - achieved by Concurrency

Examples of Poor Responsiveness

  • Waiting for Customer Support
  • Late response from a person
  • No feedback from an application

Responsiveness

  • Responsiveness can be achieved by using multiple threads, with a separate thread for each task.
  • Generally very hard to achieve otherwise.

By multi-tasking quickly between threads, the CPU can create an illusion that all the tasks are executing at the same time.

The term we use for this kind of multi-tasking is concurrency.

We don't need multiple cores to achieve concurrency. Even with one core, we can create responsive applications by using multiple threads.

Performance - achieved by Parallelism

  • We can create an illusion of multiple tasks executing in parallel using just a single core.
  • With multiple cores, we can truly run tasks completely in parallel.

Performance - Impact

  • Completing a complex task much faster
  • Finish more work in the same period of time
  • For high-scale services:
    • Fewer machines
    • Less money spent on hardware