Description
The current implementation of LocalIo
involves unsafe borrowing which doesn't transfer ownership of the IoFactory
. This unsafe code allows for mutably aliasing the IoFactory
multiple times on the stack (leading to memory unsafety).
Fixing this would involve dancing around transferring ownership of the IoFactory
between the calls that it makes. My initial idea was for LocalIo
to take ownership and give out &mut
loans to it, but this is insufficient because when a green task context switches the scheduler must again have ownership of the IoFactory
.
My best idea for doing this right now is to change all methods on IoFactory
to take ~self
and then right before the M:N methods block they would transfer ownership back to the scheduler. All the 1:1 methods would basically immediately return ownership of the factory back to the local Task
.