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).