-
Notifications
You must be signed in to change notification settings - Fork 148
Make DiarizerManager Sendable with internal locking #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make DiarizerManager Sendable with internal locking #199
Conversation
Problem: Swift 6 strict concurrency checking prevents DiarizerManager from being passed to background tasks (e.g., Task.detached) because it is a class that does not conform to Sendable. This makes it difficult to run diarization inference off the Main Actor without warnings or errors. Solution: Marked DiarizerManager as @unchecked Sendable. Introduced OSAllocatedUnfairLock to protect mutable state (models and embeddingExtractor). Added backing storage (_models, _embeddingExtractor) to support the locking mechanism. Updated cleanup() to properly nullify the embedding extractor as well. Safety Justification: Thread safety is achieved because the public API captures a local reference to the models and embeddingExtractor inside the lock before beginning long-running inference tasks. If cleanup() is called concurrently, the inference method holds onto the valid reference until it completes, preventing race conditions on the pointer.
|
actions/runner-images#13341 we are currently exping a weird bug with github job runner i have attempted means to get around the issue but so far no success |
|
@Alex-Wengg no worries, does that mean no merges till that is resolved? |
|
@saamerm they reesolved it , i will take a look |
|
just a headups we aren't on swift 6 as of this moment but we do plan to migrate soon |
|
@Alex-Wengg ah I see. I was trying to use it in the sample repo yall have “swift-scribe” which runs swift 6, so I had manually pulled the files into that project. This PR helps allow better usage away from the UI thread without workarounds |
|
we might plan to migrate to swift 6 soon |
|
Better to use Mutex in the new Or use make DiarizerManager an actor. But API will change. |
|
hi @saamerm we have just migrated over to swift 6 so this change may not be needed anymore. |
|
@Alex-Wengg sounds good, thank you |
Why is this change needed?
Problem:
Swift 6 strict concurrency checking prevents DiarizerManager from being passed to background tasks (e.g., Task.detached) because it is a class that does not conform to Sendable. This makes it difficult to run diarization inference off the Main Actor without warnings or errors.
Solution:
Safety Justification:
Thread safety is achieved because the public API captures a local reference to the models and embeddingExtractor inside the lock before beginning long-running inference tasks. If cleanup() is called concurrently, the inference method holds onto the valid reference until it completes, preventing race conditions on the pointer.