@eh FWIW, the problem you're hitting is challenging because it *is* hard to get both performance and correctness with threads. Most runtimes I'm using day-to-day "solve" this by functionally banning threads and making execution fully-deterministic (and, as consequence, sacrificing the potential performance multiprocessing allows).
If we want multiprocessing, we bundle the behavior into an entire queryable service and run it on multiple nodes. This is expensive both in terms of code labor (i.e. switching from a subroutine to an entire Dockerized service is more than a couple hours work) and overhead (now there's a whole IPC framework in the loop, if not a network fabric).
I hear rumor Erlang simplifies this but I've never looked into Erlang closely enough to really know.
@mtomczak Yeah, true. In most cases I don't need the performance. My background is Erlang where you make that trade: The (single node/thread) performance isn't amazing, but the system as a whole can be very efficient. Maybe I can get the best of both worlds (ML-like type system and easy concurrency) when Gleam becomes more mainstream. :)