Commit fac0a6d
committed
fix: add mutex to VoiceActivityDetection to prevent race between generate() and unload()
VoiceActivityDetection inherits from BaseModel but lacks the thread-safety
that VisionModel already provides. When generate() runs on a worker thread
(via ModelHostObject::promiseHostFunction) and unload() is called from the
JS thread, BaseModel::unload() destroys module_ mid-inference, causing
SIGILL/SIGSEGV crashes.
This applies the same pattern used by VisionModel:
- Add inference_mutex_ member
- Lock in generate() to protect forward() calls
- Override unload() to acquire the lock before BaseModel::unload()
Fixes #10551 parent a617188 commit fac0a6d
2 files changed
Lines changed: 19 additions & 0 deletions
File tree
- packages/react-native-executorch/common/rnexecutorch/models/voice_activity_detection
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
57 | 62 | | |
58 | 63 | | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
26 | 37 | | |
| 38 | + | |
| 39 | + | |
27 | 40 | | |
28 | 41 | | |
29 | 42 | | |
| |||
0 commit comments