2 ms·
Threads are state machines. Packaging up task state as a closure and packaging up task state as a stack do roughly the same thing. In Go, the two are closer tog
by Animats 7y ago
Threads are state machines. Packaging up task state as a closure and packaging up task state as a stack do roughly the same thing. In Go, the two are closer together than in other languages where async was a retrofit.
- lazulicurio 7y agoSure, but if you're going to go that route, why not just say "the entire computing system at a whole is just a state machine, so what's the difference"? Threads provide a very privileged form of state machine that are tightly coupled with the underlying platform. This means you have to be thinking about things like cache coherency and context switches. Without careful use of other synchronization primitives (or stronger language guarantees[1]) it's easy to find yourself writing incorrect or less-than-performant[2] code. [1] Like in Rust [2] e.g. creating bottlenecks by blocking on access to a shared resource (Edit: perhaps a better way to word that would be "accidentally reintroducing blocking behavior by using synchronization primitives to access a resource")