Created
November 8, 2020 03:46
-
-
Save godrm/02ea5a352a4b22e38af1af32a4bcbd34 to your computer and use it in GitHub Desktop.
RacyActor Phase#2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var racyGlobal: [String] = [] | |
@MyGlobalActor | |
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 | |
other.takeClass(immutableClassReference) | |
} | |
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