Working with parallel tools
There are multiple ways to implement multithreading in an application, and Chapter 6, 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 got 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 wilfully terminate), and destroy it. In other modes, 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 that then responds to requests, and performs some operations as a response to those requests. When you don...