CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. 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, https://github.com/ocaml-multicore/domainslib/pull/51#discussion_r729296762 ) 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. On Thu, Oct 13, 2022 at 6:01 AM Christophe Raffalli > wrote: Hello, I am trying ocaml 5.0 and Task.parralel_for in domainlib is not compatible with exception to interrupt the loop. When an exception is raised by a task, we need to interrupt or wait for the other tasks to finish before raising the exception. What is the recommanded solution for that pattern ? Cheers, Christophe -- Christophe Raffalli tél: +689 87 23 11 48 web: http://raffalli.eu