-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(IoT): fixing race condition in AWSIoTStreamThread .cxx_destruct #…
…5452 Related issue: #5452 Description of changes: 1. Addition of Synchronization Primitives New Properties: - dispatch_queue_t cleanupQueue - dispatch_semaphore_t cleanupSemaphore - BOOL isCleaningUp Purpose: Ensures thread-safe access and modification of critical properties like isRunning, shouldDisconnect, and defaultRunLoopTimer. Synchronization prevents race conditions during cleanup and cancellation processes. 2. Enhanced shouldContinueRunning Method Before: Used direct property access without synchronization After: Introduced synchronization using dispatch_sync for thread-safe checks Purpose:Prevents inconsistencies if multiple threads attempt to read/write properties simultaneously. 3. Cleanup Enhancements performCleanup and cleanupResources: Added explicit synchronization: dispatch_sync and dispatch_semaphore ensure cleanup operations are thread-safe and do not overlap if called multiple times. Handles complex cleanup sequences safely, such as invalidating timers, disconnecting streams, and deallocating the session. Purpose: Ensures that cleanup actions (e.g., closing streams and invalidating timers) are thread-safe and only executed once. 4. Timer Initialization Weak Reference to Prevent Retain Cycles: The timer in setupRunLoop now uses a __weak reference to avoid retain cycles Before: Used a strong reference (target:self), which could result in a retain cycle. Purpose: Avoids potential memory leaks by ensuring the thread does not retain itself via the timer. 5. Improved cancel Method Before: Simple isRunning flag and direct super cancel call After: Introduced thread-safe handling and ensured timer invalidation Purpose: Prevents race conditions when canceling the thread, ensuring timers are invalidated and properties are safely updated.
- Loading branch information
Showing
3 changed files
with
254 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.