lua-users home
lua-l archive

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



Did you check Lanes, already?

http://luaforge.net/frs/?group_id=265

I don't know Erlang, but other than that it sounds like what you're after.

I am the author, and this was my take on how multithreading _should_ (ehem) be done in Lua. Other approaches exist, as well.

As to syntax modding, that can be done with luaSub or MetaLua. Lua is a pretty modular thing; all of this does not require any changes in the Lua core itself.

From Sam's message:
Unluckily, Lua can't marshall its data structures between independent
states. If you like Erlang, you don't want global state, but projects
that have tried this before run into difficulty with marshalling
anything other than numbers, strings, and lightuserdata. You might be
able to handle tables, though recursive tables, and objects (aka
tables with metatables) are hard. You can send compiled lua functions,
and I think the debug library can return the source (compiled?) for
some functions, but people have reported problems doing this.

Lanes marshalls all of these, I think. It has some limitations, which are mentioned in the docs. Doing all this (recursive tables etc.) efficiently was tricky, but it's already done.

By default, one can throw anything at a Linda (the sharing mechanism); if it cannot be shared, one will get an error. Normally, it just flows through. And no serialization is required, either.

-asko


Timothy Baldridge kirjoitti 14.1.2009 kello 0:17:

I spent some time last year learning Erlang, and I have to say, I love
the way it works.  However, I find the syntax totally unusable for my
everyday use.

I have an idea for Lua after digging through its sources. I love Lua,
it's fast, simple and brain-dead easy to extend.What I would like to
do is add Erlang style co-currency and actor based programming models
to Lua. Basically the idea would be to spawn a separate LuaState for
each "process" (in the Erlang sense of the word). Then in the main
loop of the interpreter, we could exit early after a certain number of
OPS have been executed.

From here we can spawn n+1 OS threads where n is the number of CPUs.
By cycling through the LuaStates we should be able to keep all the
CPUs busy all the time.

My idea is to add these extra LuaStates as "children" of the first
state created. In this way all the existing C modules should/might
continue to work. Granted if two processes call the same thread we may
have issues, but hey, it's not a perfect world.

Throw into this mix a simple ! operator so we can do:
pid ! message

And we would be on the road to having Erlang style co currency in Lua.

Is anyone interested in working on this with me? I know C like the
back of my hand, I could just use some feedback/backup in the codin

--
"One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs."
(Robert Firth)