Book Image

Expert Delphi - Second Edition

By : Marco Cantù, Paweł Głowacki
Book Image

Expert Delphi - Second Edition

By: Marco Cantù, Paweł Głowacki

Overview of this book

Master Delphi, the most powerful Object Pascal IDE and versatile component library for cross-platform native app development, by harnessing its capabilities for building natively compiled, blazingly fast apps for all major platforms, including Android, iOS, Windows, Mac, and Linux. Expert Delphi begins with a quick overview of Delphi, helping you get acquainted with the IDE and the Object Pascal language. The book then quickly progresses to more advanced concepts, followed by the architecture of applications and the FireMonkey library, guiding you through building server-side services, parallel programming, and database access. Toward the end, you’ll learn how to integrate your app with various web services and deploy them effectively. By the end of this book, you’ll be adept at building powerful, cross-platform, native apps for iOS, Android, Windows, and macOS—all from a single code base.
Table of Contents (21 chapters)
Free Chapter
1
Part 1: Building Blocks
6
Part 2: Going Mobile
12
Part 3: From Data to Services
19
Index

Access synchronization

When synchronizing access, as we saw in the previous demo, one of the main issues with multithreaded applications is the need to avoid multiple threads accessing the same variable or the same resource at the same time. If one thread is making a change to a data structure while another thread is reading from it, the result will be totally unpredictable. Synchronized access to resources is the most complex issue of threading.

There are a large number of techniques you can use for thread synchronization and we don’t have the scope to explore them all extensively in this chapter. I will just introduce the most common and simple options here.

Calling Synchronize

The first option is the one we have already used: the Synchronize method of the TThread class. The idea is simple: there is some code that needs to be executed in the context of the main thread. This is the case for UI-related code, as mentioned earlier. In general, if you need to make sure...