Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Oct 3, 2025

This PR adopts Mutex on all platforms except Darwin (where we still need to back-deploy further than Mutex is available.)

Resolves #538.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@grynspan grynspan added this to the Swift 6.x (main) milestone Oct 3, 2025
@grynspan grynspan self-assigned this Oct 3, 2025
@grynspan grynspan requested a review from stmontgomery as a code owner October 3, 2025 18:07
@grynspan grynspan added the enhancement New feature or request label Oct 3, 2025
@grynspan grynspan added concurrency 🔀 Swift concurrency/sendability issues tech-debt 💾 reduces technical debt labels Oct 3, 2025
@grynspan grynspan force-pushed the jgrynspan/538-mutex branch from f31a9b9 to 6e41940 Compare October 3, 2025 18:09
This PR adopts `Mutex` on all platforms except Darwin (where we still need to
back-deploy further than `Mutex` is available.)

Resolves #538.
@grynspan grynspan force-pushed the jgrynspan/538-mutex branch from 6e41940 to 39e2c37 Compare October 3, 2025 18:10
@grynspan grynspan added the performance 🏎️ Performance issues label Oct 3, 2025
lock.initialize(to: .init())
}
#else
nonisolated(unsafe) let rawValue = rawValue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's necessary for us to write nonisolated(unsafe) here and a few other places because T isn't universally Sendable. We have some types (pointers) that we need to guard with locks which are not sendable, and the compiler is concerned there may be data races. We know what we're doing (famous last words) but the compiler can't reason about it.

@grynspan grynspan requested a review from jerryjrchen October 3, 2025 23:33
@grynspan grynspan requested a review from stmontgomery October 4, 2025 03:10
Copy link
Contributor

@stmontgomery stmontgomery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!! This is a huge simplification

@grynspan grynspan merged commit 13319e1 into main Oct 4, 2025
24 checks passed
@grynspan grynspan deleted the jgrynspan/538-mutex branch October 4, 2025 03:45
hamishknight added a commit to hamishknight/swift-testing that referenced this pull request Oct 4, 2025
stmontgomery pushed a commit that referenced this pull request Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency 🔀 Swift concurrency/sendability issues enhancement New feature or request performance 🏎️ Performance issues tech-debt 💾 reduces technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adopt Mutex
3 participants