gudzpoz / luajava

Lua for Java on Windows, Mac OS X, Linux, Android. 5.1, 5.2, 5.3, 5.4, LuaJ or LuaJIT.
https://gudzpoz.github.io/luajava/
Other
151 stars 19 forks source link

API Redesign #171

Closed gudzpoz closed 4 months ago

gudzpoz commented 5 months ago

closes #169

Planned Changes

Non-API Changes

gudzpoz commented 5 months ago

After adding more tests, LuaJ's approach to coroutines (by using OS threads) turns out to be problematic: it can deadlock.

In PUC-Rio Lua, all operations are executed a single thread:

synchronized @<thread-1> {
  lua calls another coroutine {
    lua access proxy objects {
      synchronized @<thread-1> { // luajava proxies synchronizes to ensure thread safety
        operations can be done since it it fine to nest sync-scopes in the same thread
      }
    }
  }
}

However, LuaJ uses OS threads for coroutines:

synchronized @<thread-1> {
  lua calls another coroutine {
    here is @<thread-2> !!!
    lua access proxy objects {
      synchronized @<thread-2> { // deadlock here
        unreachable~
      }
    }
  }
}

However, after looking into the implementation of LuaThread in LuaJ, it actually seems possible to re-implement coroutines with a single-threaded executor. No, it's not.

Fixed in 46ea2c3 (#171) and a24b929 (#171) .

codecov-commenter commented 4 months ago

Codecov Report

Attention: Patch coverage is 99.69605% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 96.55%. Comparing base (f6872e0) to head (09596f4). Report is 1 commits behind head on main.

Files Patch % Lines
...in/java/party/iroiro/luajava/luaj/LuaJNatives.java 90.90% 0 Missing and 1 partial :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #171 +/- ## ============================================ + Coverage 92.73% 96.55% +3.81% - Complexity 847 912 +65 ============================================ Files 43 44 +1 Lines 2368 2465 +97 Branches 281 286 +5 ============================================ + Hits 2196 2380 +184 + Misses 125 61 -64 + Partials 47 24 -23 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.