Function conc::add_garbage
[−]
[src]
pub fn add_garbage<T: Sync>(ptr: &'static T, dtor: fn(_: &'static T))
Declare a pointer unreachable garbage to be deleted eventually.
This adds ptr
to the queue of garbage, which eventually will be destroyed through its
destructor given in dtor
. This is ensured to happen at some point after the last guard
protecting the pointer is dropped.
It is legal for ptr
to be invalidated by dtor
, such that accessing it is undefined after
dtor
has been run. This means that dtor
can safely (there are exceptions, see below) run a
destructor of ptr
's data.
Unreachability criterion
If you invalidate ptr
in the destructor, it is extremely important that ptr
is no longer
reachable from any data structure: It should be impossible to create new guard representing
ptr
from now on, as such thing can mean that new guards can be created after it is dropped
causing use-after-free.
Constraints
The T: Sync
constraint is added to account for the fact that dtor
might be called in
another thread, meaning that it could cause thread-insafety if the pointer couldn't be shared.
Destruction
If the destructor provided panics under execution, it will cause panic in the garbage collection, and the destructor won't run again.