Are there any plans to add RBI support (the sending
keyword) to the OSAllocatedLock
interface? So it could be used with non-sendable objects without surrendering to the unchecked API
We can’t discuss The Future™ here on DevForums. My advice is that, if you’d like to see a change like this, you should file a bug explaining what you’d like to see changed. Please post your bug number, just for the record.
As to what you can do today, Swift’s built-in Mutex
type does have various sending
annotations. If your deployment target allows it, that’s an easy way to get this feature.
Oh, and even if your deployment target doesn’t allow you to use Mutex
, I recommend that you play around with it anyway. My experience is that it doesn’t help as much as I’d like it to. The issue is that Swift has no mechanism to indicate that a closure is only called once, so code like this doesn’t work:
import Synchronization
class Nonsendable { }
let mutex = Mutex(Nonsendable())
func test(sending instance: Nonsendable) {
mutex.withLock { state in
state = instance
}
// ^ 'inout sending' parameter 'state' cannot be task-isolated at end of function
}
So, before you file your ER, make sure that your request will actually help.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"