lua-users home
lua-l archive

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



Judging by the complete, 100% lack of response to my previous post, this topic may not be of much interest :) But on the off-chance some future archive searcher with a similar problem comes across this, I wanted to post the solution to the problem raised in my previous email.

Brief recap: I'm developing an Android app running multiple Java threads. Each thread has its own Lua state and is executing a long-running script via doString. However the scripts were executing sequentially, i.e. the second thread's script didn't start until after the first thread's script completed.

The Solution: After stepping away from the problem for a bit, the solution was quite obvious. In the LusState class, all the native functions are static! But this is not what you want because it means that all calls to, for example doSting, are using the Class object as the synchronization monitor, even if they are being called on two different Lua states.

Changing the native calls from "static synchronized native" to simply "synchronized native" restores the proper behavior--now two calls to doString on the _same_ state are sequential, while calls to doString on _different_ Lua states are concurrent.