Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Sync issues with FuturesUnordered
This updates non-mutable FuturesUnordered methods to be thread-safe, ensuring that Sync trait requirements are met without breaking existing functionality. The FuturesUnordered::link method used by FuturesUnordered::push has been modified to use atomic operations to allow for lock-free insertion of new futures while still allowing FuturesUnordered::iter and IterPinRef itself to operate simultaneously. FuturesUnordered::len has been removed, with each Task now storing a snapshot of the list length at the time when the future was added, so a synchronized list length can always be read after an atomic load of FuturesUnordered::head_all. This increases the memory overhead of each task slightly, but it allows us to retain the original iterator behavior without dramatically increasing the performance cost. Operations that require mutable FuturesUnordered access have not been made lock-free, with direct mutable access to otherwise atomic values used when possible to avoid unnecessary overhead.
- Loading branch information