Monday, 5 December 2016

Introduction to OmniThreadLibrary [2]

1.3 Installation

  1. Download the last stable edition (download link is available at the OmniThreadLibrary site, or download the latest state from the repository. Typically, it is safe to follow the repository trunk as only tested code is committed. [Saying that, I have to admit that from time to time a bug or two do creep in but they are promptly exterminated].
  2. If you have downloaded the last stable edition, unpack it to a folder.
  3. Add the folder where you [unpacked last stable edition/checked out the SVN trunk] to the Delphi’s Library path. Also add the src subfolder to the Library path. In case you are already using units from my GpDelphiUnits
  4. Add necessary units to the uses statement and start using the library! 
If you have XE8 or newer, you can download and install OmniThreadLibrary with the built-in GetIt! package manager. In that case you don’t have to manually add OmniThreadLibrary paths and you can also skip the next step (Installing Design Package). Both will be done automatically by the GetIt!

1.3.1 Installing Design Package

OmniThreadLibrary includes one design-time component (TOmniEventMonitor) which may be used to receive messages sent from the background tasks and to monitor thread creation/destruction. It is used in some of the demo applications.
To compile and install the package containing this component, follow these steps:
  • From Delphi, open packages subfolder of the OmniThreadLibrary installation and select file OmniThreadLibraryPackages{VER}.groupproj (where {VER} indicates the version of the Delphi you’re using; at the moment of writing {VER} could be 200720092010XEXE2XE3XE4XE5XE6XE7, or XE8).
  • In the Project Manager window you’ll find two projects – OmniThreadLibraryRuntime{VER}.bpl and OmniThreadLibraryDesigntime{VER}.bpl. If the Project Manager window is not visible, select ViewProject Manager from the menu.


  • Right-click on the OmniThreadLibraryRuntime{VER}.bpland select Build from the pop-up menu.
  • Right-click on the OmniThreadLibraryDesigntime{VER}.bpl and select Buildfrom the pop-up menu.
  • Right-click again on the OmniThreadLibraryDesigntime{VER}.bpl and select Installfrom the pop-up menu.
  • Delphi will report that the TOmniEventMonitor component was installed.










  • Close the project group with FileClose All. If Delphi asks you whether to save modified files, choose No.
You should repeat these steps whenever the OmniThreadLibrary installation is updated.

1.4 Why Use OmniThreadLibrary?

OmniThreadLibrary approaches the threading problem from a different perspective than TThread. While the Delphi’s native approach is oriented towards creating and managing threads on a very low level, the main design guideline behind OmniThreadLibrary is: “Enable the programmer to work with threads in as fluent way as possible.” The code should ideally relieve you from all burdens commonly associated with multithreading.
OmniThreadLibrary was designed to become a “VCL for multithreading” – a library that will make typical multithreading tasks really simple but still allow you to dig deeper and mess with the multithreading code at the operating system level. While still allowing this low-level tinkering, OmniThreadLibrary allows you to work on a higher level of abstraction most of the time.
There are two important points of distinction between TThread and OmniThreadLibrary, both explained further in this chapter. One is that OmniThreadLibrary focuses on tasks, not threads and another is that in OmniThreadLibrary messaging tries to replace locking whenever possible.
By moving most of the critical multithreaded code into reusable components (classes and high-level abstractions), OmniThreadLibrary allows you to write better multithreaded code faster.

0 comments:

Post a Comment