On Sun, Jul 30, 2017 at 4:04 PM, Dimitris Vyzovitis vyzo@hackzen.org wrote:
Quite a few words in there! Very solid exposition of a difficult problem.
Thanks!
Some first thoughts regarding implementation: We can go quite aways with two primitives:
(thread-raise! thread obj) (begin-atomic body ...)
thread-raise! is a generalization of thread-abort! that asynchronously raises an exception in the first safe-point for the target thread. A safe point is defined when interrupts are enabled _and_ asynchronous exceptions are not masked by an atomic regions.
Atomic regions are demarcated with begin-atomic, which acts like begin only its equivalent to incrementing an per-processor atomic state counter for the dynamic extent of the body. When this counter is > 0, asynchronous exceptions are masked. When the counter is decremented back to zero, a pending asynchronous exception can be raised.
No, that's not quite right. Instead, I believe that if you want "interruptible" to be the default, you still need a notion of "abstraction levels", and have a (begin-atomic level) and an (end-atomic level) that are not necessarily in the same scope, with (safe-point level forms) being a bit like (begin (end-atomic level) (begin-atomic level)), and a level attached to your thread (as a parameter?) which will be used by default when delivering an asynchronous abort (but can be explicitly lowered if you want to kill -9 your thread https://www.youtube.com/watch?v=Fow7iUaKrq4 at which point the rest of your process WILL be left in a less-than-fully functional state). For advanced uses, you'd have something like (with-safe-point-handler [level lower-level (lambda (lower-level-state) higher-level-state-form)] ...forms...).
Wrt to dynamic winds, both the wind and unwind thunks must be considered atomic. Furthermore, if the wind thunk has been evaluated, then the unwind thunk should be guaranteed to be evaluated as well in the presence of asynchronous exceptions in the body thunk.
Agreed. Optionally, the dynamic-wind would have an abstraction level such that you eschew the forms if you're willing to wholly sacrifice the abstraction level and fall back to a level below it.
—♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org None are more hopelessly enslaved than those who falsely believe they are free. — Johann Wolfgang von Goethe