[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: newproxy()
- From: Florian Weimer <fw@...>
- Date: Wed, 20 Jan 2010 21:27:00 +0100
* steve donovan:
> Is the issue that a __gc implemented in Lua can happen outside normal
> program flow and mess with the state, hence the need for a queue?
I think it's pretty difficult to write reentrant code in Lua. For
instance, storing something in a table might trigger an allocation,
garbage collection, and the condition leading to the store might no
longer be true. For instance, the following implementation of
compare-and-swap is not 100% correct (even if no metatables are
involved):
function cas(t, key, test, new)
local old = t[key]
if old == test then
t[key] = new
end
return old
end
And if you haven't got compare-and-swap, it's going to be very
difficult to write safe __gc metamethods.