[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: [Q]running Lua within multiple threads on Windows/Solaris
- From: "Virgil Smith" <Virgil@...>
- Date: Thu, 8 Apr 2004 09:54:45 -0500
Lua should be excellently suited to your purposes.
Just keep a separate lua_State per thread and then Lua will introduce 0
cross thread dependencies to your application (and thus 0 synchronization
In terms of precompiling/running Lua scripts just check out the reference
manual. You want to move away from lua_dofile to lua_loadfile or the
straight up lua_load. The load functions return a function on the Lua
stack. Calling this Lua function "runs the script". Strictly speaking this
is more than just "precompiling". However, "precompiling" can be easily
accomplished by using the load functions and then using "dump". Loading of
"precompiled" Lua byte codes can be performed using the same load routines
as "normal". This is accomplished through checking the byte values and
distinguishing between values in the "byte code range" from the "ascii
range". Someone on the list could probably give you a performance impact
analysis on that distinction or possibly point out a function that bypasses
it, but you can easily check the code to convince yourself.
I apologize if any of the function names are incorrect. The proper name for
"dump" can be found by searching the list for "string.dump".
May your efforts go smoothly.
[mailto:firstname.lastname@example.org]On Behalf Of
Sent: Wednesday, April 07, 2004 9:12 PM
Subject: [Q]running Lua within multiple threads on Windows/Solaris
This question probably has came up before, and did my best reading the
and the documentation... but I was not able to come up with an
Most messages seem to talk about the lua threads and corutines.
But I am trying to determine if LUA would be simply suited for the
I have a C++ process that runs with 10 threads (instanciated right
when the process comes up). Then from those threads I execute
independently the same C++ function. This function gets called
about 100 times a second (on a multi CPU machine). It shares no data
with other threads.
What I would like is to allow this function to call LUA, and pass
in a name of a lua script that would manipulate the a simple C structure
with about 160 fields (characters and ints). By manipulate I mean
it will just need to compare several values and then set one field to either
1 or 2 or 3.
I think what I need to
is to create a LUA context when each thread starts up with lua_open
then somehow, precompile the LUA script (perhaps for each context)
the start running the threads, to call LUA
then somehow pass the pointer to the precompiled binary
to lua_dofile (or a similar function, but I could not figure out
yet which one can take a bytecompiled), and the state L for
that given thread
Right now I just wanted to evaluate if the above would work functionaly,
then I plan to run some performance tests to see by how much the performance
of my application would degrade (I hope not by much,
because I do not plan to allocate/deallocate any memory)
So I wanted to ask if the above model is workable
Thanks in advance,
Introducing the New Netscape Internet Service.
Only $9.95 a month -- Sign up today at http://isp.netscape.com/register
Netscape. Just the Net You Need.
New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp