lua-users home
lua-l archive

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


Hi Thomas,

 

Thanks for the link to Lua 2013 workshop slides from Thomas Jericke (http://www.lua.org/wshop13/Jericke.pdf).

The solution explained starting from page 18 is close to what I tried (yield from a count debug hook).

But I’m not confident in such solution when your Lua programs also work with coroutines.

My idea is to suppress the coroutines support.

 

Thanks, Dominique Torette.

 

From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Thomas Jericke
Sent: mardi 1 avril 2014 13:17
To: lua-l@lists.lua.org
Subject: Re: Pre-emptive round robin scheduler around Lua VM

 

On 03/31/2014 02:03 PM, Dominique Torette wrote:

Hi,

 

I’m trying to build a kind of pre-emptive scheduler around Lua VM 5.2.

The idea is to execute different lua_State in “parallel’.

To give the illusion of parallelism, the idea is to run a thread for a given number of Lua VM instructions and then run the next thread in a list for this number of instructions and so on…

From the LUA regular API, when starting the execution of a thread, it is not possible to control the number of Lua VM instructions to execute.

But from the LUA debug API, it is possible to define a ‘hook’ to execute every COUNT of instructions.

The first idea was to install such hook and perform the round-robin scheduling from the hook. The lua_State of active thread seems to be saved before running such hook.

But I didn’t found any means to overwrite the thread to be resumed from the hook.

Then the idea was to ‘yield’ from the hook, back to the round robin scheduler.

This seems to work in the simplest cases. But I’ve noticed some strange “intereferences” when thread use coroutines on its own.

 

The Lua resume API has a ‘from’ parameter: int lua_resume (lua_State *L, lua_State *from, int nargs);

But from the description, I didn’t catch the how this param has to be used.

 

I’ve written a small “C” main program to illustrate the concept and the “interferences”…

In the program here below, the first iteration of the loop works as expected.

Then the L[0] and its coroutine are resumed, but the hook is reached faster than for the first iteration and the L[1] is rescheduled.

After L[0] will be never rescheduled, only L[1].

 

Thanks in advance, Dominique Torette.

 

Hi
Maybe you are interested in my talk I gave at the last Lua workshop in Toulouse:
http://www.lua.org/wshop13.html#Jericke

It includes some details how I used debug hooks to make Lua preemtive.
--
Thomas


------------------------------------------------------------------------------

E-MAIL DISCLAIMER

The present message may contain confidential and/or legally privileged information. If you are not the intended addressee and in case of a transmission error, please notify the sender immediately and destroy this E-mail. Disclosure, reproduction or distribution of this document and its possible attachments is strictly forbidden.

SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, (partly) destroyed, lost and/or belated transmission of the current information given that unencrypted electronic transmission cannot currently be guaranteed to be secure or error free.
Upon request or in conformity with formal, contractual agreements, an originally signed hard copy will be sent to you to confirm the information contained in this E-mail.

SPACEBEL denies all liability where E-mail is used for private use.

SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system.
-------------------------------------------------------------------------------