Pre-RFC: Improve the Send trait

I propose altering the Send trait as proposed by RFC #17 as follows:

  • Remove the implicit 'static bound from Send.

  • Make &T Send if and only if T is Sync.

    impl<'a, T> !Send for &'a T {}

    unsafe impl<'a, T> Send for &'a T where T: Sync + 'a {}

  • Evaluate each Send bound currently in libstd and either leave it as-is, add an explicit 'static bound, or bound it with another lifetime parameter.

The primary motivation for this is to fix some inconsistencies with the current threading model that I believe will show up when we start writing fork-join libraries (perhaps a better term would be “bounded-lifetime threads”, since that’s the interesting part). There are some pathological types may make the Sync bound inadequate, and there are a lot of concurrent types that currently require a 'static bound (like Mutex) but which I’m pretty sure could be safe to share under certain circumstances even with non-'static references with bounded-lifetime threads.

More at the link: https://gist.github.com/pythonesque/ab744000f6c656f53b7a

I’ve been thinking about this and I am in favor of this general idea, though I suspect we will want a trait Own that is basically Send+'static:

trait Own : Send + 'static { }
impl<T:Send+'static> Own for T { }

This would just be a useful shorthand for things like Box<Message+Own>

Also, I think part of this scheme is that Sync implies Send, no?

I actually modified the scheme somewhat. I no longer thing that Sync implies Send (at least, it doesn’t necessarily imply Send) though I think it could be made to do so without losing much expressiveness.

Own seems like it could be a nice convenience, and I don’t think it hurts anything, so that seems reasonable. I think it would be important to not use Own as an actual bound for anything in the stdlib, so people couldn’t accidentally impl Own for a type, though I guess that problem could be solved by making it an unsafe trait.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.