logoalt Hacker News

Stateless Actors

20 pointsby frizlabyesterday at 1:28 PM10 commentsview on HN

Comments

mayofftoday at 8:14 PM

This article is about actors in the Swift programming language, and I’d answer the question (“is a stateless actor pointless?”) differently: there is no such thing as a stateless actor in Swift.

Every actor in Swift conforms to the Actor protocol, which has one requirement: an instance property named `unownedExecutor`. Swift uses this property implicitly when, for example, the program calls a method on the actor from outside the actor.

https://developer.apple.com/documentation/swift/actor/unowne...

(One could also argue that, because every actor type is a reference type, every actor also has its identity as part of its state.)

_tk_today at 8:58 PM

You mean APTs that are not state sponsored…? Oh.

show 1 reply
mrkeentoday at 6:12 PM

A race condition:

  Two processes intend to add two to a number.

  They each read the current value.

  Then they each write back the value which is two bigger then the original.
If you instead use private fields and public getters/setters, or use actors to form a protective bubble around the mutable state, you get...

The exact same thing but with more boilerplate.

show 1 reply