Join
The Join pattern in OTL serves the same purpose as the PPL version but is implemented in a slightly different manner. The main differences are the way tasks are started and the manner of handling exceptions in background tasks. The OTL version also implements some additional functionality, which I will not explore in this book – namely, setting the number of worker threads and cancellation support.
Let’s start exploring the similarities and differences using a simple example, demonstrated in the ParallelJoin
project. The Join 2 tasks button runs the following code that starts two tasks in parallel and waits for them to finish:
procedure TfrmParallelJoin.btnJoin2Click(Sender: TObject); begin ListBox1.Items.Add('Starting tasks'); Parallel.Join(Task1, Task2).Execute; QueueLog('Join finished'); end;
Just a reminder that, in PPL, we would achieve the same with the following:
TParallel.Join(Task1, Task2...