Skip to content

Commit 3634913

Browse files
committed
Add ReentrantLock to LlmModule, matching Module.java pattern
Per reviewer feedback: the lock catches accidental unsafe concurrency from app code (double-tap, rotation during generation, missed stop()). It serializes access to non-thread-safe native state and turns silent native crashes into clear Java exceptions. Pattern matches Module.java exactly: - generate()/prefill()/load()/resetContext() use lock() - close() uses tryLock() — fails fast, no ANR risk - stop() stays lock-free (native atomic flag for cross-thread interrupt) Convenience generate() overloads delegate to terminal methods that hold the lock — the checkNotDestroyed() inside the lock is the correct check point (no TOCTOU race). This commit was authored with the help of Claude.
1 parent 42776c9 commit 3634913

1 file changed

Lines changed: 191 additions & 110 deletions

File tree

  • extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm

0 commit comments

Comments
 (0)