In-depth understanding of Actor's reentrancy issue in Swift's new concurrency model

Insert image description here

Problem phenomenon

We know that the new concurrency model introduced in Swift 5.5 greatly simplifies the development of parallel logic code. More importantly, using the Actor primitives in the new concurrency model can greatly reduce the possibility of concurrent data competition.

However, even if Actor has such magical effects, it is not a "panacea" and cannot prevent problems caused by misuse. For example: Actor reentrancy.

Actor reentry will cause the internal state of the Actor to be inconsistent, resulting in possible serious deviations in execution!

There is no so-called "one-size-fits-all" solution to the various "weird" problems you may encounter in concurrency, and there is no "silver bullet"! I believe that after studying this article, we will be able to tailor our clothes more freely, remain unchanged in response to changes, and eliminate all problems invisible!

Guess you like

Origin blog.csdn.net/mydo/article/details/133298820