lua-users home
lua-l archive

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


Hi Guys,

  While working with LuaThreads I ran into some problems while stress
  testing threads. Turns out the problem was in the file luathread.c
  in the function thread_entry.

  Original:
/* kill registry reference to thread object */
lua_pushlightuserdata(st->parent, st->child);
lua_pushnil(st->parent);
lua_settable(st->parent, LUA_REGISTRYINDEX);

  Fixed:
/* kill registry reference to thread object */
lua_lock(st->parent); // Fix Ron
lua_pushlightuserdata(st->parent, st->child);
lua_pushnil(st->parent);
lua_settable(st->parent, LUA_REGISTRYINDEX);
lua_unlock(st->parent); // Fix Ron

  This function runs on the child thread, yet it was manipulating the
  parent state without getting the lock, this would work fine most of
  the time, but under stress conditions things would go sour.

Kind Regards,

Ron