Commit 92981bf
fix: add mutex to VoiceActivityDetection to prevent race between generate() and unload() (#1056)
## Description
Add thread-safety to `VoiceActivityDetection` using the same mutex
pattern already established by `VisionModel`.
Without this, `BaseModel::unload()` can destroy `module_` on the JS
thread while `generate()` is still calling `forward()` on a worker
thread, causing `SIGILL` / `SIGSEGV` crashes.
### Introduces a breaking change?
- [x] No
### Type of change
- [x] Bug fix (change which fixes an issue)
### Tested on
- [x] Android
### Testing instructions
Use `useVAD({ model: FSMN_VAD })` with continuous audio input and
trigger rapid mount/unmount cycles. Confirm no crashes or deadlocks.
### Related issues
Fixes #1055
---------
Co-authored-by: Bartosz Hanc <bartosz.hanc02@gmail.com>1 parent 7dcc391 commit 92981bf
2 files changed
Lines changed: 11 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: 5 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 | + | |
26 | 29 | | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
0 commit comments