awaiting a spawn_local JoinHandle is not Send even if the Output is Send
- Dominant language
- Rust
- Stars
- 4.1k
- Forks
- 339
- PR merge metrics
- No merged PRs in 30d
Description
To be clear - I am not 100% sure if this is supposed to work, but I think I have reason to believe it reasonably should work.
I have an example at https://gist.github.com/Fishrock123/82e742454a844914513be49738e4a34e where a `Mutex` inside an `Arc` is moved into a `spawn_local` from an outer `task::spawn`, but fails to compile with this error:
```
`std::sync::MutexGuard<'_, Inner>` cannot be sent between threads safely
```
This is strange, because I am going through the effort to prevent exactly this, by only accessing the `Mutex` from within a `spawn_local`. This seems to only occur if the `Mutex`'d struct has an async function called from it. In my case, that's happening with `&mut self`. I _believe_ that an async function at this point should not require `Send`, since it is all running within the same thread, absent any other `task::spawn`s, but I guess it does, for some reason? The error is particularly bizarre, and probably also a compiler output bug, because it seems to refer to the wrong things in general.
The example also compiles if the outer `task::spawn` is also `spawn_local`, which is undesirable in the actual code this example is based off of _(I want a thread / threadpool for a queue reading client)_.
Contributor guide
Assessment
This issue has not been assessed yet.