Monday 18th June.

Continuing our Multi Threading theme from last month, Jarrod Hollingworth presented a master-class in advanced threading:

Topics included:
– Demonstrate the new Delphi parallel library (parallel for loop, tasks run in thread pool, joins and futures)
– Thread safety (expanding on what was shown with critical sections, mutex/semaphore, TEvent, interlocked increment, etc)
– Tips, techniques, issues (stopping a thread, more on interacting with the main thread, debugging)

Jarrod started with an overview of threading fundamentals.
He then demonstrated TParallel.For and showed how it may start with just one thread, then add extra threads if they seemed to be needed.
He showed how easy it is to get incorrect results if you don’t code multi-threading correctly, and showed that even the Inc function was not thread safe.
He explained that the Atomic functions (AtomicIncrement, AtomicExchange, etc) could be used to safely modify a shared field.

We then learned about TTask and how to wait for tasks to finish, and learned about Futures.
Jarrod covered various ways of coordinating multiple threads, and discussed advantages and disadvantages of each technique. He timed some examples so we could compare their speed.
He also mentioned the NameThreadForDebugging function, that is used to label a thread in the debugger.

The slides he showed can be downloaded from More! Multi-threaded Development
There is a list of resources on the last page of these slides.

Two of the demonstrations he used can be downloaded:
Conway’s Life (TParallel.For) from https://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RADStudio_Tokyo/Object%20Pascal/RTL/Parallel%20Library/
Delphi Academy – Parallel Library (Parallel Squares, TTask, Future) from http://cc.embarcadero.com/Item/30754

The meeting was held at the Melbourne Men’s Shed, situated in the Federation Square Car Park building, off Russell St Extension.