[fpc-devel] Exceptions in threads

Mattias Gärtner nc-gaertnma at netcologne.de
Thu Dec 11 14:21:07 CET 2008

Zitat von Florian Klaempfl <florian at freepascal.org>:

> Mattias Gärtner schrieb:
> > I'm writing a unit to simplify parallel methods/procedures.
> >
> > For example:
> >   DoParallel(@AMethod,StartIndex,EndIndex,Data);
> >
> > The AMethod is executed with several threads in parallel.
> >
> > What should happen when an exception occurs?
> > It would be nice if the exception can be transfered to the main thread.
> > Is this possible? How?
> See synchronize/checksynchronize implementation.

Sorry, I misused the term 'main thread'.

DoParallel starts AMethod with several threads in parallel and waits until all
threads finished. DoParallel can be called by any thread (e.g. the main thread
of the process *or* any other sub thread). Even the threads of the pool can
call again DoParallel. This is only limited by the memory, as each call creates
a threadgroup object.

The goal is to simplify parallelizing procedures so for the user DoParallel
should work like a normal procedure call.
That's why it would be nice if the following could work:


The exception can occur in any of the subthreads including the starting thread
(which I named 'main thread', because it is the main thread of the group. Maybe
I should call it 'group thread' or 'starter thread').

When an exception occurs, the group waits for all other threads of this group to
finish and then the exception should happen 'as if the exception occured in the
starting thread'.


More information about the fpc-devel mailing list