hackclub / putting-the-you-in-cpu

A technical explainer by @kognise of how your computer runs programs, from start to finish.
https://cpu.land
MIT License
4.71k stars 145 forks source link

Cooperative multitasking is still a thing #15

Open gevial opened 11 months ago

gevial commented 11 months ago

Hi,

Just noted in the end of Chapter 2 it reads “ For these reasons, the tech world switched to preemptive multitasking a long time ago and never looked back.” It looks like a bit of overstatement because concepts like coroutines and green threads are quite popular nowadays, and we even have quite popular languages built on top of that (Go with its goroutines). Appreciate language runtime-level cooperative multitasking is not the same as OS-level, but still worth mentioning I think.

Overall, a great write-up that I very much liked to read!

thanks!

itoshkov commented 10 months ago

The cooperative multitasking is still a thing, but on language level, not OS level. This is because on language level you don't have one of the problems - having malicious or badly designed program stealing all the resources. Your program still can be badly designed and have some thread steal all the CPU time allocated for the process for itself. But this is a bug in your program and you can fix it. Whereas if OS uses coop multitasking, bad design in somebody else's program can clog the whole system.