-
Notifications
You must be signed in to change notification settings - Fork 7
Conversation
Note: servo/servo#21325 is waiting on this PR. |
src/default.rs
Outdated
#[inline] | ||
fn with_handle<F, R>(mut f: F) -> R | ||
where | ||
F: FnMut(&Handle) -> R, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe FnOnce would be better, since it's only called once anyway? This might require a slight change in the code however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, that doesn't compile and I don't know how to do better.
error[E0382]: capture of moved value: `f`
--> src/default.rs:49:50
|
49 | HANDLE.try_with(|h| f(h)).unwrap_or_else(|_| f(&COLLECTOR.register()))
| --- ^ value captured here after move
| |
| value moved (into closure) here
|
= note: move occurs because `f` has type `F`, which does not implement the `Copy` trait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I thought that it might work with a match statement, however after trying it I see that it doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think you can pass f
directly to try_with
right? It doesn't need an extra closure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an extra closure. :) Otherwise we get this:
error[E0382]: capture of moved value:
--> src/default.rs:49:39
|
49 | HANDLE.try_with(f).unwrap_or_else(|_| f(&COLLECTOR.register()))
| - ^^^ value captured here after move
| |
| value moved here
|
= note: move occurs because `f` has type `F`, which does not implement the `Copy` trait
use crossbeam_utils::thread; | ||
|
||
#[test] | ||
fn pin_while_exiting() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this only meant to not abort? If so a comment explaining that would be useful, now the test doesn't really make much sense.
src/default.rs
Outdated
} | ||
|
||
/// Returns the default handle associated with the current thread. | ||
#[inline] | ||
pub fn default_handle() -> Handle { | ||
HANDLE.with(|handle| handle.clone()) | ||
with_handle(|handle| handle.clone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is removed in #84.
If we try to call
pin()
when exiting the thread, it is possible that we'll access the thread-localHANDLE
after it has already been destroyed.This is sometimes a problem when using
crossbeam-epoch
while the thread is unwinding from a panic. In that case, double panics cause aborts.To fix the problem, we register a temporary
Handle
in caseHANDLE
has already been destroyed.