lua-users home
lua-l archive

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


Hi Thijs Schreijer

You told
You can only acccess a lua state from a single thread. So assuming you stay single threaded, then for each invocation you can simply clear the stack, and do your thing. Nobody will interfere with that.

In above are you telling that lua state can be accessed from a single thread. If in one process I have 10 threads, and from 10 threads I am trying to access lua state, will it be a sequential execution hence a performance issue. will not 10 threads access lua state in parallel.


In another case when I have 1000s of processes, and say that from each process a single thread is accessing lua state. Is it that only one process can access lua state at a time, again a risk of sequential execution of processes.

Kindly clarify on above.



On sandboxing question, I hope you preferred "do luaL_openlibs once at C code init time and lua_close
  at C code exit time
" .  Though it looks it will be preferred one from performance perspective, what are other implications. Since I have 1000s of processes, how much system resources like semaphore, shared memory, mutex etc will be present per lua state. What extra RAM usage will be there per lua state keeping it active throughout.

When we have 1000s or 10,000s processes running in a machine, can I really dare to go for above approach.

Many thanks for your kind help.

Austin










On Tue, Jun 24, 2014 at 4:33 PM, Thijs Schreijer <thijs@thijsschreijer.nl> wrote:


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Austin Einter
> Sent: dinsdag 24 juni 2014 11:50
> To: Lua mailing list
> Subject: Re: Simple Function Call From C language
>
> Hi Thijs Schreijer
> Basically I am using lua related functions such as
> 1. luaL_checkinteger(L, -1);
> 2. lua_pushinteger(L,4);
> in my C code.
> Once I call pushInteger api, do I need to call corresponding popInteger (or
> similar) api so that stack in Lua or in C will be in tact. For me there will
> be 1000s of processes and any process can call any Lua specific apis
> randomly. So bit worried if I am messing up a bit with stack.

You can only acccess a lua state from a single thread. So assuming you stay single threaded, then for each invocation you can simply clear the stack, and do your thing. Nobody will interfere with that.

>
> One more question is, suppose a C program is running for 1 hour. Frequently
> Lua scripts will be executed from C code.
> Is it a good idea to do luaL_openlibs once at C code init time and lua_close
> at C code exit time.
> Or whenever I want to execute a script, do luaL_openlibs , then execute Lua
> api, and then do lua_close.
> If I have 10 scripts to execute, do 10 times luaL_openlibs and lua_close.
>
> Which approach will be better.

This is a sandboxing question. Will users enter code, might it be malicious? Then you need tight controls, for example, some of the functions in the debug library you would better remove then.

Your first approach would be my favourite, but let each script run in its own environment that can be cleaned up by the GC after it finishes. Performance wise I think this would be best.

Thijs

> Thanks
> Austin
>
>