lua-users home
lua-l archive

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

2015-01-04 5:45 GMT-08:00 mniip <>:
> Per-state mutexes will be quite tricky to implement, as you don't really have
> per-state variables. You can have a reference to the same table in two
> coroutines. You can even have access to the same local numeric value from two or
> more coroutines if you pass a function around that have it as an upvalue.
> One way to implement per-state mutexes is for every TValue to have an "owner"
> state, so you lock that state mutex before dealing with the value. This will
> probably require huge efforts and will increase size of TValue, which is not
> good (OK, on 64bit architectures, you can squeeze in 32bit index without size
> penalty as TValue is being padded to 16 bytes anyway, that is in Lua 5.2).

Yeah I'm rethinking it right now, they won't be per-state mutexes but per-object
mutexes. But you don't have to lock TValues at all! You only have to lock
GCObjects. The only case, I think, where 2 states may simultaneously access the
same TValue is tables, but at that point it's easier to just lock the whole
table (which is a GCObject by the way).

/* mniip */

I think per-object mutexes won't provide very much useful critical region definition. For example, see the following code,

some_package.some_function(exp.prop, exp.prop2)

It involves accesses to three properties to two tables. How do you define the critical region? Do you lock and unlock each table before and after each access to a property? Do you lock both tables in the duration of the entire line? How do you achieve the latter without extend Lua syntax to expose explicitly PV?