Comment by storystarling
4 hours ago
How are you handling shared state with the new concurrency primitives? Since it is embeddable I am curious if you went with a global lock approach like Python or isolated states similar to Lua. Managing thread safety while keeping the C API simple is usually the hardest part of these implementations so I would love to hear more about the architectural choices there.
I added a section to https://git.xw3.org/fun/fun/src/branch/main/docs/internals.m... that describes this more detailed. I copied from other documents some seconds ago and I am not sure if this all is 100% correct actually. I will check this and will update the file if I find some wrong parts...
I chose isolated state (like Lua) rather than a single global lock (like Python’s GIL). Each VM has its own heap, scheduler, and garbage collection. There are no cross-VM pointers. Concurrency and data exchange happen via message passing and a few carefully scoped shared-memory primitives for high‑throughput use cases. This keeps the C API simple, predictable, and safe to embed in multi‑threaded hosts.