lua-users home
lua-l archive

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


Hello,

I've done an initial port of Lua 5.0 to eCos (http://www.sourceware.org/ecos).
Files are available at http://devel.elatec.si .

Now I'am looking to implement multitasking using eCos native threads.
I've started working with the code from LuaThreads and got most of things
running. The mayor problem is that the mutex (used in lua_lock/lua_unlock)
(wich is shared between the parent and child threads) is locked while inside
the main loop of interpreter (luaV_execute). Because of this an thread running
code like 'while 1 do x=x+1 end' can't be preempted by its parent or sibling
threads. The simplest way of solving this seemd to be the following change inside luaV_execute function:

   if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
       (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
     traceexec(L);
#ifdef __ECOS
   }
   lua_unlock();
   lua_lock();
{ #endif
     if (L->ci->state & CI_YIELD) {  /* did hook yield? */
       L->ci->u.l.savedpc = pc - 1;
       L->ci->state = CI_YIELD | CI_SAVEDPC;
       return NULL;
     }
   }

Is this safe ?

thanx

savin