lua-users home
lua-l archive

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


It was thus said that the Great Leo Romanoff once stated:
> > 
> > I'm not sure if it can be done, but could you use the lock/unlock macros to 
> > perform the yield?
> 
> Can you elaborate a bit? Where I should use such macros? In the C code? Or in Lua? 
> If it is in C, can I invoke such a C-function which does lock/unlock from Lua?
> And how is it different from lua_yield that can be used in C?

  He's talking about two C macros in llimits.h which are there so you can
add an implemention (in C).  They're there to make Lua thread safe (as in,
multiple operating system threads can share the same Lua state).  What is
being suggested is that at each point in the C code that comprises Lua hits
a point that two independent threads could cause data corruption is
protected via a lua_lock()/lua_unlock() pair (for instance, two threads
sharing the same Lua state attemp to modify the same table).

  What you are trying to do is somewhat similar---doing an implicit "yield"
in the middle of an operation could lead to problems.  

  I don't know enough about the internals of Lua to say if this is a good or
bad idea, but it would be something I would look into.  

  -spc (I slowly coming to the idea that pre-emptive multitasking is no
	longer a Good Thing(TM) but I still need to formulate my thoughts on
	this)