Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RacyActor Phase#2
var racyGlobal: [String] = []
var safeGlobal: [String] = []
class PlainOldClass {
var unprotectedState: String = []
actor class RacyActor {
let immutableClassReference: PlainOldClass
func racyFunction(other: RacyActor) async {
// protected: global variable protected by a global actor
safeGlobal += ["Safe access"]
// unprotected: global variable not in an actor
racyGlobal += ["Racy access"]
// unprotected: racyProperty is immutable, but it is a reference type
// so it allows access to unprotected shared mutable type
func takeClass(_ plainClass: PlainOldClass) {
plainClass.unprotectedState += ["Racy access"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment