Summary
While this chapter focused on a single topic, it was still quite diverse. You’ve learned everything about the TThread
class, which is a basis for all multithreading code in Delphi. Even the task-based approach that we’ll explore in the next chapter uses TThread
as a basic building block.
I have shown three different ways to create a TThread
-based multithreading solution. A program can take complete ownership of a thread so that it is created and destroyed by the owner. This approach is best used when a thread implements a service, as in cases where the main program knows best when the service is needed.
Another method, which is more appropriate for background calculations, is FreeOnTerminate
mode. With this approach, a thread object is immediately destroyed when a thread’s Execute
function exits. The thread owner can set up an OnTerminate
event to catch this condition and process the result of the calculation.
Instead of writing a separate class...