Skip to content

Clarify use of unsafe in extra::arc #9251

Closed
@sfackler

Description

@sfackler

extra::arc::MutexArc contains two sets of methods to access the Arc's wrapped object. unsafe_access and unsafe_access_cond are tagged unsafe as "it is possible to construct a circular reference among multiple Arcs by mutating the underlying data. This creates potential for deadlock, but worse, this will guarantee a memory leak of all involved Arcs." There are also access and access_cond methods defined when the inner type is freezable as that guarantees the type can't contain a MutexArc. However, it's still trivially easy to deadlock using the safe methods:

extern mod extra;

use extra::arc::MutexArc;

fn main() {
    let arc1 = MutexArc::new(());
    let arc2 = arc1.clone();

    do arc1.access |_| {
        do arc2.access |_| {
        }
    }
}

It seems that the consensus in #2821 was that possibility of deadlock is inherently unsafe, so should access and access_cond be removed?

cc @bblum

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