You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -125,8 +125,8 @@ It would be safe to send a type across the thread boundary only if it's aliased
125
125
To avoid to talk about plain borrows, consider `Rc<'a, T>` implemented using new `Cell<'a, usize>` as a reference counter.
126
126
It is safe to send `a: Rc<'a, T>` to another thread if there isn't any other `b: Rc<'a, T>` left on the old thread.
127
127
But more than that, if there is another `b: Rc<'a, T>`, we still could send both of them `(a, b)` across threads.
128
-
I have found type annotation for [higher-ranked lifetimes]`(a, b): for<'a> (Rc<'a, T>, Rc<'a, T>)`, although formally ambiguous, to be quite fitting.
129
-
Now you can see yourself why `&mut T` would be just a non-copyable version of `for<'a> &Cell<'a, T>`.
128
+
I have found type annotation similar to [higher-ranked lifetimes]`(a, b): unalias<'a> (Rc<'a, T>, Rc<'a, T>)`, to be quite fitting.
129
+
Now you can see yourself why `&mut T` would be just a `unalias<'a> &Cell<'a, T>`, which means this type has to be uncopyable before instantiating `'a` with a free lifetime.
130
130
131
131
From this we could even restore the original `Send` oriented design.
132
132
The `!Send` implementation on a type essentially tells that utilized memory region could be (non-atomically, without synchronization) aliased from the *current thread*.
@@ -138,10 +138,27 @@ The solution to that problem would be to abstract assumption into a type, let's
138
138
But you shouldn't be able to prove that `'a` aliasing lifetime does not occur somewhere else, so you won't ever be able to send it across threads.
139
139
Any function requiring thread-unsafe access to thread-locals would have to get this type through its arguments.
140
140
This then would be reflected in the function signature, which would inform whether function body is sendable across threads or not.
0 commit comments