lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 9-Feb-07, at 3:07 PM, Doug Rogers wrote:

Clever! It will be laborious to verify its operation under all cases and
conditions. But we live to labor, do we not?

No doubt. :)

I should have mentioned the one issue with that approach. Normally, we want finalizers to be timely (otherwise, we could have just used the garbage collector); finalizers implemented with the upvalue mechanism will certainly be timely if execution does not do a coroutine.yield() -- since the finalizers are not implemented with pcall, that's actually possible.

Now, we might have different views about what should happen if a thread yields; in essence, we certainly want finalizers to run if the thread is never going to be resumed, but it's hard to know that in advance. So that leaves the finalizer running when/if the thread is garbage collected.

Since that's somewhat unpredictable, many people prefer dynamic windows to finalizers; the idea being that when an invariant is maintained *while the thread is active.* If the thread yields, the invariant can be broken (for example, a lock can be released) provided that it is restored before the thread is resumed. That may be too complicated for a language like Lua (indeed, finalizers themselves may be too complicated); certainly, experience with such mechanisms in Lisp and Scheme suggests that they work fine when used correctly, but they are very easy to get wrong.