Skip to content

Trait bounds for SharedMutex loose #2

@ammaraskar

Description

@ammaraskar

Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that SharedMutex implements Send and Sync so long as the contained type is Sync:

unsafe impl<T: ?Sized + Send> Send for SharedMutex<T> {}
unsafe impl<T: ?Sized + Sync> Sync for SharedMutex<T> {}

However, this should be Send + Sync bound just like the standard library's Mutex requires Send. There are some types such as MutexGuard which are safe to use across threads but can't be sent (in the case of MutexGuard this is because it's undefined behavior to acquire and free a lock from a different thread). There's more examples here: https://users.rust-lang.org/t/sync-but-not-send/21551

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions