lua-users home
lua-l archive

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


On Tuesday 15 February 2005 18:52, Ben Sunshine-Hill wrote:
> Apologies if I'm missing something obvious, but under this patch, what
> features are in place to prevent resource leaks with a C function that
> allows yielding after having locked a resource, and then is never
> resumed (thread is GCed)? Obviously, one could stick a userdata on the
> stack with a custom __gc for cleanup, but is there a less roundabout
> way?

I'd have thought that you just wouldn't do that. You'd have to define that 
certain Lua API functions allowed yielding; programmers would then have to 
ensure that any resources were known about by the garbage collector.

i.e.:

{
 mutex->lock();
 lua_pcall(...);
 mutex->unlock();
}

...is forbidden, but:

{
 push_lock(L, mutex);
 lua_pcall(...);
}

...isn't. (push_lock would push a magic value onto the stack that represented 
the mutex lock; when it gets garbage collected, the lock would be freed.)

Lots of scope for nasty, indeterminate errors and memory leaks, but you'd 
probably have to live with that...

-- 
"Curses! Foiled by the chilled dairy treats of righteousness!" --- Earthworm 
Jim (evil)