If I understand correctly, you are asking about cancellation for Domainslib tasks, specifically for Task.parallel_for.
(I would have created an issue against Domainslib to ask. Interestingly, I can find only one vague mention of cancellation there,
)
I haven't tried it, but I would think that the simple approach is to turn
Task.parallel_for ~start ~finish pool ~body:(fun i ->
... raise Exit ...
)
into
let stop : exn option Atomic.t = Atomic.make None
Task.parallel_for ~start ~finish pool ~body:(fun i ->
Option.iter raise (Atomic.get stop);
.. (Atomic.set stop Exit; raise Exit) ...
)
which guarantees prompt termination by checking a shared failure value at each iteration of the loop. But of course this adds a small amount of overhead, which may be undesirable if each loop iteration is supposed to be very fast. (Then the simple approach
is to change "Option.iter" into "if i mod 100 = 0 then Option.iter ...".)
This is an instance of the general approach of letting users do cancellation explicitly on their side, if they want to.