Skip to content
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

Manual Synchronization should show modern locking patterns with Sendable #62

Open
ktoso opened this issue Jun 13, 2024 · 3 comments
Open

Comments

@ktoso
Copy link
Member

ktoso commented Jun 13, 2024

We have developed some patterns to limit the "just sprinkle @unchecked Sendable on it" on codebases.

We should showcase some of our recent locks:


Maybe we should take the chance to show good lock patterns here.

Like for example https://github.com/apple/swift-nio/blob/main/Sources/NIOConcurrencyHelpers/NIOLockedValueBox.swift
which is just:


public struct NIOLockedValueBox<Value> {
    
    public init(_ value: Value)

    public func withLockedValue<T>(_ mutate: (inout Value) throws -> T) rethrows -> T
}

extension NIOLockedValueBox: Sendable where Value: Sendable {}

Or also the new Mutex type -- we can ask https://github.com/swiftlang/swift-evolution/blob/main/proposals/0433-mutex.md @Azoy to provide a small snippet

@FranzBusch
Copy link
Member

I agree. If using new new Mutex most types don't even have to use @unchecked Sendable since Mutex is unconditionally Sendable. @unchecked Sendable is required with atomics though.

@mattmassicotte
Copy link
Collaborator

I think this would be excellent content, and might have a nice home in some kind of "Design Guidelines" article. That's come up many times.

@ktoso
Copy link
Member Author

ktoso commented Jun 13, 2024

And we can mention I think we mention OSAllocatedUnfairLock as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants