-
Notifications
You must be signed in to change notification settings - Fork 20
Thread-safety in a mixed Rust/C++ code base #73
Copy link
Copy link
Open
Labels
l-rustChanges that are mainly in RustChanges that are mainly in Rustp-safetySafety or soundness related problems or use casesSafety or soundness related problems or use casesp-semanticsLanguage semantics differencesLanguage semantics differencessolved-crubitSolved by CrubitSolved by Crubitt-problem-statementA description of an interop problemA description of an interop problem
Description
Activity
Metadata
Metadata
Assignees
Labels
l-rustChanges that are mainly in RustChanges that are mainly in Rustp-safetySafety or soundness related problems or use casesSafety or soundness related problems or use casesp-semanticsLanguage semantics differencesLanguage semantics differencessolved-crubitSolved by CrubitSolved by Crubitt-problem-statementA description of an interop problemA description of an interop problem
Rust and C++ have very different views on how thread-safety works and how it is documented: a C++ method may be thread-safe or -unsafe independent of its const-ness, and it all basically depends on just documentation. In Rust the information is in the type system with
SendandSync.In a world where C++ class instances are regularly passed into Rust, it falls upon the Rust bindings to divine whether that object can be sent to a foreign thread (
Send), and which of its methods areSync. It is also not necessarily clear if thread-safe methods can be expressed in Rust as taking&selfdepending on the field declarations:The
&selfhere promises to Rust that bothstatic_anddata_stay unchanged, but the FFI call actually mutatesdata_: on the Rust side we should be wrappingdata_in anSyncUnsafeCellbut that is generally impossible to figure out from just the header declarations.