Skip to content

Unable to use hashbrown sctuctures between threads #2

@Shchvova

Description

@Shchvova

It seems like hashbrown structures doesn't implement Send making it very hard to use them in multithreaded applications

For example, attempt to return them from thread via join handle:

extern crate hashbrown;
fn main () {
    std::thread::spawn(move || { hashbrown::HashSet::new() } );
    std::thread::spawn(move || { hashbrown::HashMap::new() } );
}

Wouldn't compile

➜  cargo build
error[E0277]: `std::ptr::NonNull<u8>` cannot be sent between threads safely
 --> src/main.rs:4:5
  |
4 |     std::thread::spawn(move || { hashbrown::HashSet::new() } );
  |     ^^^^^^^^^^^^^^^^^^ `std::ptr::NonNull<u8>` cannot be sent between threads safely
  |
  = help: within `hashbrown::HashSet<_>`, the trait `std::marker::Send` is not implemented for `std::ptr::NonNull<u8>`
  = note: required because it appears within the type `hashbrown::raw::RawTable<(_, ())>`
  = note: required because it appears within the type `hashbrown::HashMap<_, ()>`
  = note: required because it appears within the type `hashbrown::HashSet<_>`
  = note: required by `std::thread::spawn`

error[E0277]: `std::ptr::NonNull<(_, ())>` cannot be sent between threads safely
 --> src/main.rs:4:5
  |
4 |     std::thread::spawn(move || { hashbrown::HashSet::new() } );
  |     ^^^^^^^^^^^^^^^^^^ `std::ptr::NonNull<(_, ())>` cannot be sent between threads safely
  |
  = help: within `hashbrown::HashSet<_>`, the trait `std::marker::Send` is not implemented for `std::ptr::NonNull<(_, ())>`
  = note: required because it appears within the type `hashbrown::raw::RawTable<(_, ())>`

.....

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