Hi Rustaceans,
I’m new to Rust. As my first project I’m reimplementing a multi-threaded programm with a central RDF-graph as knowledge base.
For working with RDF I wrote some Rust-bindings for the Redland API. I wrapped the pointers I get from C in Rust-structs.
To communicate with the RDF-data in multiple threads I wrote some Management-struct. The problem I’m now facing is that my wrapper-structs contain *mut ptr causing the wrappers not to implement neither Send or Sync. I thought that if I wrap my Manager in an Arc<Mutex<>> sending to multiple threads wouldn’t be a problem because the Mutex ensures mutual exclusion therefore making the unsafe *mut ptr threadsafe.
Have you experienced Rustaceans some advices how I could fix this issue?
That’s one of my compiler errors:
error[E0277]: `*mut librdf_rs::extern_c::world::CLibrdfWorld` cannot be shared between threads safely
--> src/adapter/mod.rs:30:13
|
30 | thread::spawn(|| {
| ^^^^^^^^^^^^^ `*mut librdf_rs::extern_c::world::CLibrdfWorld` cannot be shared between threads safely
|
= help: within `semantic_management::RdfFactory`, the trait `std::marker::Sync` is not implemented for `*mut librdf_rs::extern_c::world::CLibrdfWorld`
= note: required because it appears within the type `librdf_rs::World`
= note: required because it appears within the type `semantic_management::RdfFactory`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<semantic_management::RdfFactory>`
= note: required because it appears within the type `adapter::semantics::SemanticAnnotator`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Mutex<adapter::semantics::SemanticAnnotator>`
= note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::Arc<std::sync::Mutex<adapter::semantics::SemanticAnnotator>>`
= note: required because it appears within the type `adapter::Adapter`
= note: required because it appears within the type `&adapter::Adapter`
= note: required because of the requirements on the impl of `std::marker::Send` for `&&adapter::Adapter`
= note: required because it appears within the type `[closure@src/adapter/mod.rs:30:27: 35:14 self:&&adapter::Adapter]`
= note: required by `std::thread::spawn`