Multi-processing vs multi-threading vs async-await vs Goroutine

LORY
10 min readJul 2, 2023

All about async programming

Beginning

During the developer interview, below are some common misunderstandings about processing, threading, and async-await. such as

  • “For CPU-bound tasks, always use multi-processing, it is 100% faster than multi-threading”
  • “Multi-threading is similar to asyncio in Python. asyncio will also start a thread, the same as threading”
  • “Multi-threading is only good for I/O tasks because multi-threads can not be executed by multiple CPUs at the same time if they are in the same process”
  • “When called another async within one async function, it started another thread, and when calling ‘await’, which is the same as ‘thread. join()’”
  • “Golang is fast, it is made for concurrency. it is always 100% faster than other languages when doing parallelism”

Hope you will agree with me, all the above, are wrong, or partially correct.

let’s discuss them one by one.

So think about you are going to eat Mc Donald’s with your friends today.

Blocking I/O

So you and 2 of your friends walked into McDonald’s. you ordered a first meal. your friend must wait until your order is completed.

This is a blocking model. The whole process is slow and easy to understand.

In CS terms.

  • “You” and 2 friends are function calls.
  • the “Queue” is the process itself.
  • “Waiter” is the main thread (in user space) of the process.
  • “Kitchen” is the kernel space.
  • The “Cook” is the kernel thread which doing the task.

So now let’s continue with multi-threading to speed it up.

Multi-threading

Note: the below model is not for Python. To add some Python favor, scroll down a bit there is a “waiter” in front which stands for the…

--

--

LORY

A channel which focusing on developer growth and self improvement