[Lazarus] Multithreadprocs and breaking out of loop

Mattias Gaertner nc-gaertnma at netcologne.de
Fri Aug 20 16:42:07 CEST 2010


On Fri, 20 Aug 2010 15:15:34 +0300
"Juha Manninen (gmail)" <juha.manninen62 at gmail.com> wrote:

> Hi
> 
> I tried multithreadprocs package, explained in wiki:
>  http://wiki.lazarus.freepascal.org/Parallel_procedures
> 
> I works well. Cool!
> 
> Question: how to break out of a paralled loop in a clean way?
> 
> The problem is finding something from blocks of data. 
> There are more blocks than there are threads. It would be enough to prevent 
> new threads starting. The currently running threads can run to the end.
> 
> Should I throw an exeption and then catch it outside the 
> ProcThreadPool.DoParallel(...) call?

Yes, that works.

 
> The best solution could be added to the wiki page, too.

I doubt there is one best solution for all problems.

You could use a boolean flag Abort somewhere. It does not even need a
critical section.


Mattias




More information about the Lazarus mailing list