File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ extern "C" {
22
22
23
23
type SharedOption < T > = Arc < Mutex < Option < T > > > ;
24
24
25
+ // The `Send` bound on `F` is necessary for safety. Although we are not
26
+ // worried about data races since control flow from one thread to the other
27
+ // is sequential, objects captured by `f` might have implementations
28
+ // sensitive to some thread state (ID, thread-local storage, etc).
29
+
25
30
pub fn r_task < ' env , F , T > ( f : F ) -> T
26
31
where
27
32
F : FnOnce ( ) -> T ,
66
71
* result. lock ( ) . unwrap ( ) = Some ( res) ;
67
72
} ;
68
73
69
- // Move `f` to heap and erase its lifetime
74
+ // Move `f` to heap and erase its lifetime so we can send it to
75
+ // another thread. It is safe to do so because we block in this
76
+ // scope until the closure has finished running.
70
77
let closure: Box < dyn FnOnce ( ) + ' env + Send > = Box :: new ( closure) ;
71
78
let closure: Box < dyn FnOnce ( ) + Send + ' static > = unsafe { std:: mem:: transmute ( closure) } ;
72
79
You can’t perform that action at this time.
0 commit comments