Skip to content

Conversation

@Ddystopia
Copy link
Contributor

Each mutex is generated uniquely for each task, it is unsound to send them between tasks. But they are Send. Before, it wasn't an issue, because you couldn't share non-'static data between them, but with #1043 you can make the mutex 'static. Thus we need to use actual tools that Rust provides and out out from Send.

Currently, mutexes are simple ZSTs with PhantomData<&'a ()>, which is Send. We replace it with PhantomData<(&'a (), *const u8)>, and return Sync back via unsafe implementation. It is trivially sound, because mutexes have
no method methods that accept &self. See https://doc.rust-lang.org/std/sync/struct.Exclusive.html for details.

Each mutex is generated uniquely for each task, it is unsound to send
them between tasks. But they are `Send`. Before, it wasn't an issue,
because you couldn't share non-`'static` data between them, but with
\rtic-rs#1043 you can make the mutex `'static`. Thus we need to use actual
tools that Rust provides and out out from `Send`.

Currently, mutexes are simple ZSTs with `PhantomData<&'a ()>`, which is `Send`.
We replace it with `PhantomData<(&'a (), *const u8)>`, and return `Sync`
back via `unsafe` implementation. It is trivially sound, because mutexes have
no method methods that accept `&self`.

See https://doc.rust-lang.org/std/sync/struct.Exclusive.html for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant