Working with parallel tools
There are multiple ways to implement multithreading in an application, and Chapter 8, Working with Parallel Tools, dealt with the most basic of them all—TThread
. This class was introduced in Delphi 2 where it simply wrapped the Windows CreateThread
API. Later, it was enhanced with additional methods and added support for other operating systems but, in essence, it stayed the same good old, stupid, clumsy TThread
, which we all learned to love and hate.
Threads created with TThread
can be used in two modes. In one, the code has full control over a TThread
object—it can create it, tell it to terminate (but the object must observe that and willingly terminate), and destroy it. In the other mode, the code just creates a thread that does its job, terminates it, and is automatically destroyed. The former is more appropriate for service-like operations. You start a thread, which then responds to requests and performs some operations in response...