hawkw / sharded-slab

a lock-free concurrent slab (experimental)
MIT License
269 stars 17 forks source link

check out references with an arbitrary lifetime #29

Closed hawkw closed 3 years ago

hawkw commented 4 years ago

Feature Request

Currently, the Guard and PoolGuard types borrow the Slab/Pool and return a guard with the 'a lifetime, where 'a is the lifetime of the Slab or Pool. This ensures that references to entries don't outlive the Slab/Pool that owns them.

However, the generic lifetime means that these guards may only be stored on the stack. They cannot be placed in any type which must have a 'static lifetime, or live on the heap for an unknown amount of time.

We might want to consider adding a way to check out an owned reference, when the Slab/Pool is in an Arc. Since &Arc<Self> is a valid receiver type, we can do this. In this case, we would return a different type of guard, which clones the Arced Pool/Slab into the guard. This would ensure that the reference keeps the slab that the referenced item lives in alive.

In this case, we would have to use an *const T (probably should actually be a NonNull) for the actual reference to the object. But, this is fine, since the Arc keeps the owner alive --- we just can't prove this to the compiler.

hawkw commented 4 years ago

@bIgBV are you interested in working on this one? If not, I'll probably crank it out.

bIgBV commented 4 years ago

I can have something working by tomorrow. @hawkw