Skip to content

sync::mutex::StaticMutex disappeared from public API, perhaps unintentionally? #19379

Closed
@emk

Description

@emk

This seems to have been removed here, as part of the sync cleanup for #19274: 689ef2d

The commit message says:

Because this removes the libsync crate, it is a:

[breaking-change]

However, all uses of libsync should be able to reroute through
std::sync and std::comm instead.

My use-case for StaticMutex was protecting global state in C libraries in emk/rust-cld2 using code like:

extern crate sync;
use sync::mutex::{StaticMutex, MUTEX_INIT};

static LIBRARY_LOCK: StaticMutex = MUTEX_INIT;

fn access_global_resource() {
    let _ = LIBRARY_LOCK.lock();
    unsafe { call_thread_unsafe_c_api(); }
}

Is there a clean way to do this with guards, etc.? I suppose I could use Once to bootstrap my way up to a global mutex, and use that to guard call_thread_unsafe_c_api, but that seems a lot more complicated than using StaticMutex. Am I simply missing the obvious solution here?

Thank you very much for working to rationalize sync!

cc @bors @alexcrichton

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