[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Read only objects
- From: Mildred <ml.mildred593@...>
- Date: Sat, 12 Apr 2008 20:37:11 +0200
I'm thinking about how it could be possible to get Lua working in a
preemptive multithreaded environment. And I was thinking about a way
this could be done without sharing writable memory.
Well, the idea isn't new, it comes from the COP model that can be found
on the Lisaac language documentation <http://home.gna.org/isaac/>
(but not yet implemented).
So the idea is to be able to have multiple threads running
concurrently. Those threads won't be able to have shared writable
objects. If they share an object, this object must be read-only. Thus
it solves the problem when multiple threads are modifying the same
object at the same moment.
The idea continues to allow threads to call functions on other threads.
These function call are stored in a fifo queue and executed when
possible. If a function call requires a result, the call is blocking.
Otherwise it's not blocking. And of course, all arguments to these
function call are transformed into immutable objects (read-only) before
the call. This should be recursive (table members, environment,
So I was wondering how it could be done in Lua. Actually, I don't have
any knowledge about Lua internals, that's why I'm asking you.
I think that the only thing that is needed to implement this
cooperative model is the ability to:
- make an object immutable
- be able to copy (or perhaps make a reference) immutable objects from
one lua universe to another, without creating side effects that would
cause problems when the two lua universes are used concurrently (that
should be possible if the objects are immutable)
Do you think it's possible ? Easy to do ?
I know that it is possible to serialize objects ... But somehow I don't
think that's the right solution. And I don't think you can serialize
everything (how do you serialize functions and their upvalues ?)
XMPP: <email@example.com> (GoogleTalk, Jabber)
GPG: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]