-
Notifications
You must be signed in to change notification settings - Fork 11
Support for no_std #4
Comments
|
We also need to expose a way to get a |
Good idea. Just something to keep in mind: this method must be marked as unsafe because you can cause use-after-free with it (assuming that we get rid of the #[derive(PartialEq, Eq, PartialOrd, Ord)]
struct Key<'a>(&'a i32);
impl<'a> Drop for Key<'a> {
fn drop(&mut self) {
println!("dropping: {}", self.0);
}
}
let c = Collector::new();
{
let boxed = Box::new(7);
let s = SkipList::with_collector(c.clone());
s.insert(Key(&*boxed), ());
s.remove(Key(&7));
}
drop(c); // Oops, the key is now getting dropped and printing `boxed`.
Actually, it's not hard to do - I already did that in one of my local branches. :) Each And note that returning a |
Is there much demand for non- The problem with returning a |
I imagine keys might often be of type An alternative to removing pub unsafe trait DeferredDropSafe {}
unsafe impl<T: Copy> DeferredDropSafe for T {}
unsafe impl<T: 'static> DeferredDropSafe for T {} This way we can have
Note that struct Collector {
global: Arc<Global>,
} The idea is to simply replace the |
pub unsafe trait DeferredDropSafe {}
unsafe impl<T: Copy> DeferredDropSafe for T {}
unsafe impl<T: 'static> DeferredDropSafe for T {} I don't think this will work: the 2 trait impls conflict with each other. |
That is, unfortunately, true at the moment. FWIW, it compiles with |
If I'm not mistaken, epoch can't currently support no_std because it performs allocation which relies on the global allocator. There is no global allocator in a no_std environment. |
The intention is to support it running in a |
Gotcha. An alternative that would be useful for us (and honestly maybe not too many other users) would be to have |
As a first step, I'm thinking we should publicly expose
base::SkipList
and present it as the 'advanced' skip list implementation targeted at expert users who want to use the skip list inno_std
, control garbage collection more precisely, passGuard
s to methods, squeeze out every ounce of performance, and so on.Secondly, in
no_std
we don't have access toepoch::pin()
so one should useHandle::pin()
instead and pass a guard to methods that work with theSkipList
.When passing a guard to a skip list method, we must make sure that the guard belongs to the same
Collector
the skip list is using. In other words, every method taking a&Guard
should have a check at the beginning like in the following snippet:In order to be able to make such checks, we'll have to first implement
fn Guard::collector(&self) -> &Collector
incrossbeam-epoch
.In addition to that,
SkipList
would probably need a similar method returning a reference to its ownCollector
.With such an interface, I envision the skip list might be used like this:
@Amanieu What do you think about all this - would this interface work for you? Any better ideas for supporting
no_std
?The text was updated successfully, but these errors were encountered: