Swift Actor Question

First of all, in any circumstances don’t use semaphores with actors. There are a few threads on deadlocks caused by semaphores in actors and in Swift Concurrency in general.

The simples solution is to avoid suspension points in such method. But that might be not always possible.

As alternatives, is to serialize access with own queuing, that has been addressed in a several topics, like this one:

You can search for more, there were a few with a long discussions, nice details and examples.


I’ve recently came across old post by @ktoso in early times of concurrency discussion that was saying that in theory reentrancy can be also addressed by introducing additional actors that will encapsulate reentrant operation. I haven’t explored it yet, but seems like an interesting approach, which also might be more robust in basic implementation.

4 Likes