H IGH - LEVEL M ULTITHREADED P ROGRAMMING [P ART I] Primož Gabrijelčič
B ACKGROUND I NFORMATION
About Me Primož Gabrijelčič Programmer, consultant, writer, speaker – thedelphigeek.com – Working with Delphi since Delphi 1 Hacking multithreaded code since 1999
About OmniThreadLibrary „VCL for multithreading“ Delphi 2007 – XE3[4] Open source – OpenBSD license – – omnithreadlibrary.googlecode.com Win32/Win64
About the Webinars Code and video: Code = free, video = $10, bundles! 20 free books, courtesy of the De Novo Software,
Installation Download the installation package from the Google Code or checkout the SVN repository Add installation folder and its src subfolder to the project search path or Win32/64 library path Add the OtlParallel unit to the uses list
Documentation Blog tutorials “The book” Presentations Forum Google+: #omnithreadlibrary
Why Multithreading? Improve performance Improve responsiveness
H IGH -L EVEL A BSTRACTIONS
Why? Designing parallel solutions is hard Writing multithreaded code is hard Testing multithreaded applications is hard Debugging multithreaded code is pure …
OTL to the Rescue! Well-tested components … packed in reusable classes … with high-level parallel programming support.
High-Level Abstractions Async [/Await] Future Join ForEach ParallelTask BackgroundWorker ForkJoin Pipeline
Which abstraction to use? Consider data flow!
High-Level Abstractions Async [/Await] Future Join ForEach ParallelTask BackgroundWorker ForkJoin Pipeline Start background task and continue
Async [/Await]
High-Level Abstractions Async [/Await] Future Join ForEach ParallelTask BackgroundWorker ForkJoin Pipeline Start background calculation and retrieve the result
Future
High-Level Abstractions Async [/Await] Future Join ForEach ParallelTask BackgroundWorker ForkJoin Pipeline Start multiple background tasks [and wait]
Join
P ARTING N OTES
Keep in Mind Don’t parallelize everything Rethink the algorithm Data flow dictates the abstraction Measure the improvements Test, test and test
Code and Video