dmulholl / pyro

A dynamically-typed, garbage-collected scripting language.
https://www.dmulholl.com/docs/pyro/master/
BSD Zero Clause License
7 stars 0 forks source link

Fibers rather than threads? #1

Closed gvwilson closed 1 month ago

gvwilson commented 2 years ago

Hi - thanks very much for making Pyro available. Have you thought about adding Wren-style fibers (co-operative multi-tasking) rather than threads? Seems like it would be much less difficult (both to implement and to use), and it would be a clean way to provide non-blocking I/O. Thanks again, Greg

dmulholl commented 2 years ago

Hi Greg, to be honest I haven't really thought about the best way to implement concurrency yet -- I decided to punt that question off until the core design of the language had settled down first.

I will definitely take a look at Wren's fibers -- that's an approach I've never seen before and it does look like a really interesting option for a scripting language.

Thanks for the suggestion!

gvwilson commented 2 years ago

I think Nystrom borrowed it from Lua and Erlang, and I vaguely remember it from working with real-time systems a looong time ago. Gives the language generators for free, doesn't lead to callback hell, plays nicely with libuv's event loop - looking at the Wren source code, it looks like replicating the stack and stack pointer would be pretty straightforward; I'm still trying to wrap my head around error handling: if a child fiber panics and the parent doesn't handle it, the parent panics - what happens to the siblings of the fiber that originally panicked?