[fpc-pascal] Re: getting started with threads
tobias_subscriber at tgtools.com
Fri Sep 18 04:07:19 CEST 2009
> But how can I prevent race conditions? If threads X and Y happen to
> call the task assignment function at the same time, it seems to me
> that they could both be assigned to the same task.
Use for example the cross-platform implementations of
Enter/LeaveCriticalSection. Like this:
> Then the main loop can assign a new task by starting a new thread,
> whenever it finds one > that is finished.
Also possible but not easier. Threads should not be started or
stopped for each task, instead they should wait for an event telling
them to continue with the next task. For example using SetEvent /
ResetEvent as well as:
More information about the fpc-pascal