Apple proposes actor model for Swift concurrency

Apple proposes actor model for Swift concurrency

Swift language proposal would add actors as a way to prevent data races and other common bugs in concurrent programming

Credit: Dreamstime

Apple has published a proposal to add an actor model to the Swift programming language. The goal is to provide a mechanism that prevents data races in the Swift concurrency model.

A Swift evolution proposal in the active review stage, posted on GitHub, notes that the actor model would provide the ability to use shared mutable state while providing static detection of data races and other common concurrency bugs.

An actor is a reference type (introduced by the keyword actor :) that protects access to its mutable state. In response to messages, an actor can make local decisions, send more messages, create more actors, and decide how to respond to the next message received.

Actors can modify their own private state but only affect each other indirectly through messaging, thus eliminating the need for lock-based synchronisation.

A concurrency roadmap for the Swift language published last fall included a proposal for actors and actor isolation. A structured concurrency proposal for Swift introduces concurrent tasks and provides data race safety for functions and closures.

While this model is suitable for some design patterns, including parallel maps and concurrent callback patterns, it is limited to working with state captured by closures. Although Swift includes classes that provide a mechanism for declaring mutable state that is shared across a program, classes are difficult to use within concurrent programs.

The actor proposal is set to be reviewed until March 29. The review process was opened on March 15.

Follow Us

Join the newsletter!


Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Tags AppleSwift

Show Comments