It might be worth nothing that Actor
s and Task
s together can create deadlocks. Reposting example from an earlier thread:
actor Deadlock {
var task: Task.Handle<Int>?
func getValue() async -> Int {
if task == nil {
task = detachedTask {
return await computeValue()
}
}
return await task!.get()
}
private func computeValue() async -> Int {
return await getValue() + 1
}
}
Here we end up with a task depending on its own result, so any call to the actor's getValue
will await
indefinitely. A deadlock of the infinite suspension kind.
Claims that actors can't deadlocks have to be taken with a grain of salt. It's true if you consider actors in isolation, but as part of a bigger system they can still end up deadlocked.
My conclusion is that we don't need non-reentrant actors because we already have them.