grump wrote: ↑Fri Nov 24, 2017 3:17 pm
Is it possible, for a future version, to implement a mechanism for reporting thread errors that works like an exception instead of an event?
No, because lua itself isn't thread-safe. There is no way to interrupt the main thread, so it has to poll, in this case via the event loop.
grump wrote: ↑Fri Nov 24, 2017 3:17 pm
Or maybe a way to bind channels to threads and make them release their block when the thread isn't running anymore.
I don't know how that can be done cleanly. Channels are many-to-many communication channels, if there are multiple threads waiting, which one gets the error? Or if the thread that errors has multiple Channels it somehow wants to interrupt, how would that work?
The only solution that comes to mind (and I don't know how I would implement it yet) would be some multi-wait primitive, like the posix select call. Something that would allow you to say "Wake me up when I receive a message on one of these channels, am done sending a message on one of these other channels or when one of these threads errors" or some subset of that.
bartbes wrote: ↑Fri Nov 24, 2017 4:58 pm
I don't know how that can be done cleanly. Channels are many-to-many communication channels, if there are multiple threads waiting, which one gets the error? Or if the thread that errors has multiple Channels it somehow wants to interrupt, how would that work?
The only solution that comes to mind (and I don't know how I would implement it yet) would be some multi-wait primitive, like the posix select call. Something that would allow you to say "Wake me up when I receive a message on one of these channels, am done sending a message on one of these other channels or when one of these threads errors" or some subset of that.
In my opinion it would be sufficient if the timeout mechanism on demand() would not just accept a timeout duration, but also an optional list of threads. demand() returns as soon as a) data arrives or b) the timeout duration has been reached or c) all (or any?) of the threads are in the dead state. There's no need to discern between 'error' and 'dead' for this, IMHO.
If that is not possible or not clean enough, there's another thing that would help a little bit with the error situation: if newThread did not just load but parse the code, syntax errors would be detected in the main thread before Thread:start is called.