Skip to content

Mutable statics are difficult to use correctly #269

@Diggsey

Description

@Diggsey

The documentation gives an example of "correct" usage of a mutable static, where a hypothetical "atomic_add" function is called.

https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics

However, AIUI this code is incorrect as soon as a mutable reference is created to the static variable, as the lack of synchronization means that the mutable reference may alias.

This means that mutable statics can only be used when you already have some method of synchronization in place. Unfortunately this makes mutable statics quite useless. For example: a typical use of a mutable static might be to store a libc::sem_t semaphore type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions