> 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: EnterCriticalSection(MyCritVar); try DoStuff finally LeaveCriticalSection(MyCritVar); end; > 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: {$ifdef win32} WaitForSingleObject(ContinueEvent,INFINITE); {$else} RTLEventWaitFor(ContinueEvent); {$endif} Cheers, Tobias _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal