David Lewis - 2014-07-08

I've found a much cleaner way to achieve this, but it's library invasive. The following (or similar, not fully tested) would allow users to cleanly dispose of coroutines that have been suspended and will never be resumed.

This is not a very complete treatment of the problem, but it does provide a neat and specific mechanism to get around it.

LuaThread.State

:::java
private boolean abandoned = false;

...

public public synchronized LuaValue lua_abandon() {
    if(this.status == STATUS_SUSPENDED) {
        this.abandoned = true;
        notify();
        return LuaValue.TRUE;
    } else {
        return LuaValue.FALSE;
    }
}

...

233: if (this.lua_thread.get() == null || this.abandoned) {

..