Tangent128 / luasdl2

A pure C binding of SDL 2.0 for Lua 5.1, Lua 5.2, and LuaJIT.
ISC License
385 stars 74 forks source link

channel first/last method results in deadlock #78

Closed fastcoding closed 3 years ago

fastcoding commented 5 years ago

I always got deadlock when use channel.first/push/pop. noticed that there might be issue with the codes.

static const Variant *
channelFirst(const Channel *c)
{
    Variant *v;

    SDL_LockMutex(c->mutex);
    if (STAILQ_EMPTY(&c->queue))
        return NULL;   //<---- here return without unlock mutex ???

    v = STAILQ_FIRST(&c->queue);
    SDL_UnlockMutex(c->mutex);

    return v;
}
markand commented 3 years ago

Good catch, I'll address a fix but I'm unsure if I'll keep the thread/channel API because I think they don't belong to the SDL library and there are other Lua modules for real threads.

markand commented 3 years ago

Oh, nevermind it was already fixed.