James
James

Reputation: 41

Is there a way to exit a thread in a Parallel.foreach loop which is stuck

I am using OmniThread Parallel.foreach(). There are instances where the loop takes a long time or gets stuck.

I would like to know, is it possible to timeout each process in the Parallel.foreach() loop?

Upvotes: 0

Views: 304

Answers (1)

H.Hasenack
H.Hasenack

Reputation: 1164

In short: Nope, there isn't.

Unless you program the timeout handling in your 'thread body' code (what gets called in the execute).

eg my database engine allows sending a CancelProcessing call to running queries from a different thread that runs the query, this would 'cleanly' end the running subthread.

'Dirty' end of the subthreads:

I added a FR to Omnithread's github site to add an (Dirty) Terminate method to the IOmniParallel interfaces (and alikes). Which has is drawback because killing subthreads will probably leave you with memory/resource leaks.

Meanwile you might use this dirty shutdown solution/workaround wich actually comes down fixing a similar problem (I had a deadlock in my parallel processed routine, so my parallel.Waitfor never returned true, and worse my IOmniParallelTask interface variable was never released causing the calling thread to block as well.

Upvotes: 0

Related Questions