[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua and preemptive scheduling for coroutines
- From: Leo Romanoff <romixlev@...>
- Date: Fri, 29 Mar 2013 02:38:55 -0700 (PDT)
----- Ursprüngliche Message -----
> Von: Sean Conner <sean@conman.org>
> An: Leo Romanoff <romixlev@yahoo.com>; Lua mailing list <lua-l@lists.lua.org>
> CC:
> Gesendet: 10:29 Freitag, 29.März 2013
> Betreff: Re: Lua and preemptive scheduling for coroutines
>
> 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.
OK. Thanks for clarifications.
> -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)
In principle, I agree with this. But I'm also not sure that explicit cooperative multi-tasking is such a good thing. I think that cooperative implicit multi-tasking (with ability to control at the meta-level or higher-level how cooperation happens, e.g. by means of custom policies or something like this) is more bullet-proof.
-Leo