I wondered if it would be possible to safely send &T
or &mut T
from one thread to another, while using rust's lifetimes to ensure that the reference lived long enough. refcapsule is my attempt at implementing that.
It's roughly modeled off of the current implementation of scoped threads in the standard library, but instead of waiting for all child threads to complete, it waits for the wrappers for all passed references to be dropped.
I'm not entirely sure if I got all the unsafe parts correct, or if I am missing something that would result in UB.
I don't have any particular use case in mind for this. It was more a curiosity project to see if it was possible.