In fork-join concurrency scenario (here's an example of what the interface may look like)
it may happen that we would want to pass Arc<Mutex<Vec<&mut int>>>
to child threads (you can imagine that instead of int
there's really big structure that parent thread could access only by reference, so I think it's a pretty reasonable scenario).
So we want to wrap Vec<&mut int>
in a Mutex
, but that requires Send
and our vector doesn't fulfill Send
.
So to be able to do that, we may just remove Send
bound from Mutex::new
. We may think that it won't introduce any unsafety,
because Send
or 'static
bound will be checked by spawn
or similar methods anyway.
But unfortunately, now we are able to pass Arc<Mutex<Rc>>
too, which for sure shouldn't be legal, because of internal, non-thread safe, mutability of Rc
.
So my proposed solution is to keep Send
bound for Mutex::new
, but decouple Send
from 'static
. Send
would only mean "has Sync env