Skip to content

Manual Synchronization should show modern locking patterns with Sendable #62

@ktoso

Description

@ktoso

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions