Fibers, Oh My (2020)
graphitemaster.github.io
graphitemaster.github.io
The best fiber interfaces, like virtual threads in Java, intercept these blocking primitives and perform the yield there implicitly. This means that user code just doesn't need to worry about this at all and can block as they normally would.
https://github.com/slouc/concurrency-in-scala-with-ce
I also later distilled it into this one:
Would be fun to believe that something I wrote inspired parts of this one, but in reality it's probably just a case of great minds thinking (and sounding) alike :)
Anyway, I'm glad to have found this great text. I agree with the author's statement that "there’s a distinctive lack of good information online", because I felt the same way writing mine. Thanks hn and whoever (re)posted this.
Fibers, Oh My - https://news.ycombinator.com/item?id=24679740 - Oct 2020 (69 comments)
(Reposts are fine after a year or so; links to past threads are just to satisfy extra-curious readers)
Deadlocks are still possible when using fibers backed by a single thread if you serialize your fiber execution. Here’s an example I’ve seen in the wild:
Imagine a serialized job server implemented with fibers that, when closed, waits for all jobs to finish by posting a final bookend job and waiting for it to finish. This works, unless you decide to close the server inside one of your serialized jobs—you’ve now created a deadlock where your job server is waiting for itself to finish closing.
I’m sure an N:1 deadlock is also possible without serialization, but I can only think of contrived examples.
Being able to meaningfully support 500K users on a single mid-grade server was also great for the pocketbook. (When I saw the sheer scale of the Twitter servers a while back, I was gasping for air).
Why does the author say "possible"? Isn't it basically always the case that a modern computer is running as many threads in parallel as it has cores?
I wasn't "making a point". I was asking a question. My question is why the author said "possible": since this is an educational piece of writing, isn't it misleading to say "possible"? Am I right in thinking that basically all computers in common use now (e.g. phones, laptops, desktops, machines used in corporate data centers) have multiple CPU cores? And furthermore, that they are basically always executing instructions simultaneously on all cores? (Instructions from some userspace process or the kernel)