Skip to content

How strongly can you rely on the absence of nonatomic? #757

@madsmtm

Description

@madsmtm

The author of a library controls the synthesis / implementation of an Objective-C property with the atomic/nonatomic attribute, see the docs on properties. Properties are atomic by default.

This means that something like @property NSString* name;, by default, would be safe to read / modify concurrently (though not necessarily correct in the presence of other fields like lastname, but that's a separate thing).

It is unclear whether we're allowed to rely on the attribute as consumers though? Because a lot of headers may use @property (because it's the default), but in reality implement the property getter/setter as just a plain read/write of an instance variable. I.e. in reality be nonatomic without declaring that.

As a data point, this StackOverflow answer says:

If you are writing your own setter/getters, atomic/nonatomic/retain/assign/copy are merely advisory.

Would be interesting to see if Swift uses the attribute anywhere? And maybe there are some frameworks where we can say it's safe to rely on the absence of the nonatomic attribute to indicate an actually atomic property (probably Metal?), and others where we can't?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frameworkAffects the framework crates and the translator for themquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions