Rust non-joinable fiber API
In tarantool fibers have different feature flags which can be switched using the ffi api. One of such flags is is_joinable (there's also a is_cancellable flag, which is covered in a separate ticket #30 (closed)). This flag works such that if a fiber is joinable, and it completes the execution (fiber function returns), then the fiber's resources (stack memory, etc.) are not released until fiber_join is called on it. The logic AFAICS is that if you want to spawn a fiber which is going to do some job in the background and you don't care when it terminates, you mark it non-joinable.
Currently the fiber::start and fiber::defer families of functions create fibers which are marked joinable, and there's no way to create a non-joinable fiber using these functions. In fact the join handles returned from these functions will panic if dropped without calling join on the fiber. This sucks because people end up either calling std::mem::forget on the join handles, which leaks the fiber's memory forever, or carry the join handles around in some storage and have to implement a system for when join needs to be called just to clean up the memory.
The only way to create a non-joinable fiber is to use the deprecated Fiber::new api, which is ugly and lame. So we should add this ability to the new api.
Here's an idea, we can add a method to the fiber join handles (there's multiple types of those), which makes the fiber non-joinable while consuming the join handle itself. Something like:
let jh = fiber::start(|| {
while !time_to_die() {
do_important_work();
}
});
jh.make_non_joinable(); // This takes `self` by value, so nobody can call `jh.join()` anymore
// Now the fiber runs in the background and will be automatically cleaned up when it's time for it to die
NOTE: This method should only be available for unit join handles, i.e. fibers which don't return a value, otherwise it makes no sense.