3 min read
No, he can’t fly.
When normal kids want to make a hot chocolate and binge-watch YouTube, they can do it at the same time:
The difference is that our kid waits until some task is done and, only after that, is he able to start the next one. Other kids perform tasks simultaneously and don’t wait until the prior task is completed.
Just like single-threaded languages are different from multi-threaded ones. Single-threaded languages can perform only one task at a time, while multi-threaded languages can perform them in parallel (all at the same time).
It's all about how the threads work.
Threads. Slides. Dogs.
In programming, threads are essentially single processes that a program can use to perform tasks. You can think of this like a water slide where performing a task is the process of going down the slide.
Yes, it's a dog. It represents a task.
This is how your computer works: each thread can execute only one task at a time. Everything else is blocked until an operation is completed. When one dog goes down the water slide, the other dogs have to wait. Only one dog in the water slide at a time. Only one task at a time in a thread.
Thread. Aquapark. Our child has grown up.
Imagine that our special kid grew up and decided to open a water park for dogs. This isn’t a normal water park. He applied his “single-threaded philosophy of life" to it.
Unfortunately, he can't.
He is a special kid and we must accept his single-threadedness. No matter how hard he tries to imitate multithreaded behavior with setTimeout(..., 0) and web workers, he will remain single-threaded.
He will remain our special kid.
PS: no dogs were harmed in the process of writing this article.
In the end...
If you enjoy this article you need to know that every Monday, I send a letter to 4,000+ Web Developers with 3 hand-picked articles from the tech world, 2 web development guides, and 1 best Tweet of the week
“Your newsletter is f**king awesome, really Nick. It gives me a great start to the week with a lot of insightful knowledge.”
Join smart developers who get short and full of knowledge letters for free.