ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
559 stars 72 forks source link

eio_linux: allow alloc_fixed_or_wait to be cancelled #753

Closed talex5 closed 2 months ago

talex5 commented 2 months ago

As noted in #752, waiting for a fixed buffer couldn't be cancelled. This adds support for that.

I'm using this PR to test out the Picos style of cancellation. Normally, Eio programs set a cancel function to be invoked immediately when the fiber is cancelled, but Picos instead just schedules the cancelled fiber to be resumed and the clean-up actions happen later.

The new style introduces an annoying extra state, where the operation is half-cancelled (the cancellation has happened, but the fiber is still registered as waiting for a buffer), and we need to handle that by retrying. On the other hand, it means no user code runs in the scheduler's context, and potentially allows cancellation from another domain.