The DAPUG Multithreading Workshop begins with a
general overview of multi-threaded development. This discussion
includes when and why you should create additional threads of
execution in your code, and when you should avoid doing so. It also
covers those situations where you have no choice, those in which
your code is executing in threads over which you have no control,
such as when your code is executing in an ISAPI DLL or in response
to an Internet Direct server.
Next, we discuss the fundamentals of creating and
managing threads, with focus on Delphi's TThread class. Topics
covered in this section include why and how to create a thread in a
suspended state, how to control a thread's priority, and how to
properly terminate a thread. Why the suspend and resume methods have
been deprecated are also discussed. This section concludes with a
look at Delphi's thread debugging features, including those
debugging options introduced since Delphi 2009.
Here is where is gets really interesting. While
threads are not so difficult to control, they introduce the
potential for major problems. In short, when two threads have access
the a common resource things can go very wrong. Fortunately, there
is a handy solution called synchronization, and Delphi provides a
wide variety of synchronization options. In this section you will
learn the advantages and limitations of each of these traditional
options.
It's now time to slow things down for a moment,
and consider some of the classic thread-related bugs. These include
thread starvation, race conditions, and thread priority inversion.
How to spot these bugs will be discussed, and possible solutions
will be presented.
Finally, it's time to look at Delphi's latest
thread-related features. Since Delphi 2009, Delphi's support for
multi-threaded development has grown significantly. Here we will
look at the newest classes, records, and methods that you can use in
your applications. Included in this discussion are TMonitor,
TThreadedQueue, TSpinLock and TSpinWait, and anonymous threads. This
section will necessarily include a discussion of generics and
anonymous methods.