Single thread lock
To understand asynchronous / parallel / multithreaded, we need to start from the very basics and WHY we have added so many difficulties to the problem.
In the beginning, there were only single-threaded applications for locking. These are really simple programs, and most likely this is what you are writing right now.
To explain, I will use the pizza house analogy.
Imagine your computer is a one-person pizza house. He had only basic training.
You go to the store, talk with the employee, look at the menu and order pizza.
Great. An employee enters the back of the store, puts pizza on top and stands next to the oven, waiting for the pizza to cook .
Do you remember that your wife does not like pineapples. You are shouting at an employee, trying to attract his attention to change your order. No dice. He will not move from the stove (he fell asleep).
You get annoyed and leave.
Multithreaded parallel blocking
You go to the next pizza shop.
It has 4 employees.
You go to the store, talk with the employee, look at the menu and order pizza.
He screams (sends a message) to other employees in the back to make pizza. They put one in the oven. He stands next to the oven and sleeps.
You forget that your wife is allergic to bacon. You tell employee A to cancel the pizza. He screams inside the cook, wakes him up. The cook throws the pizza into the hopper and puts the kosher pizza in the oven. He quickly fell asleep.
Wait, the pizza is ready, you will get the bill. Its massive (hiring too many employees, and half of them sleep at work).
Single-Threaded Asynchronous / Non-Blocking
You go to the next pizza shop.
He has 1 employee.
You go to the store, talk with the employee, look at the menu and order pizza.
He goes inside, puts the pizza in the oven. He then attaches a receipt ( callback ) to the pizza. He returns to the counter.
Do you remember that your wife didnβt really eat meat this month. You tell the employee, he goes inside, fixes the situation.
After the employee checks inside for the made pizza. Then he reads the receipt (give this pizza to Bob).
You get a cheap affordable and responsive pizza.