Download presentation
Published byEllen Boyd Modified over 9 years ago
1
Building Multithreaded Solutions with OmniThreadLibrary
The only URL you have to write down: Primož Gabrijelčič,
2
Ask how was at the previous presentation and maybe replay few slides from it (stuff about OTL)
OmniThreadLibrary
3
OmniThreadLibrary Multithreading library for Delphi 2007/2009⇨
Task oriented Strong messaging support Can be used with any threading infrastructure High level parallel programming
4
Project Status Free “As in Air” -Theo de Raadt Available
OpenBSD license Available code.google.com/p/omnithreadlibrary/ Actively developed 830 commits Used downloads of the latest release Almost no documentation otl.17slon.com/tutorials.htm 830 commits in 2 years 3 months 1776 last time I looked; 1.05a was released in March Plethora of examples Almost no documentation
5
Today’s Topics Communication vs. Shared data Tasks vs. Threads
Thread pools
6
I’ll show the communication-related code later, together with task-related code
Tasks
7
Task <> Thread Task is part of code that has to be executed
Thread is execution environment You take care of the task, OTL takes care of the thread
8
Execution Models CreateTask(task_procedure) CreateTask(task_method )
CreateTask(TOmniWorker_object) CreateTask(anonymous_procedure)
9
Just a short info on thread pools before I open the Delphi …
10
Thread pool Starting up a thread takes time
Thread pool keeps threads alive and waits for tasks Automatic thread startup/shutdown User code executed at thread creation Connection pool .Run ⇨ .Schedule Automatic – according to parameters specified by the programmer (min/max threads, max idle time)
11
Communication
12
Shared Data Pros Cons Keep in mind Only one copy Fast if only reading
Locking Bad scaling Deadlocks, livelocks Keep in mind Fine-grained is better Optimistic locking Fast if not modified: copy on write
13
Messaging Pros Cons No shared data - no* locking Hard to understand
Increased memory usage *For sufficiently flexible definition of “No” Hard to understand = sometimes Increased memory usage = sometimes
14
Common Sense Sometimes you need both Minimize shared data
Minimize interaction points “If your solution depends on sharing data million times a second, you’re doomed.” -me And it doesn’t matter if you’re locking million times a second or sending million messages a second.
15
Messaging Solutions Windows messages Pipes Mailslots Sockets (TCP/IP)
Shared memory + (micro)locking Used by the OmniThreadLibrary communication primitives “shared memory” in context of “shared data inside application” not “memory shared between processes”
16
Messaging in the OTL Bounded stack Bounded queue Dynamic queue
Dynamically allocated, O(1) enqueue and dequeue Useful for single-threaded applications too All are threadsafe, microlocking, and support multiple readers and writers All are lock-free (or micro-locking), all are threadsafe, all support multiple readers and writers Bounded = size specified at creation
17
TOmniValue Used in OTL messaging Record with operators
Can contain strings, interfaces, objects … Faster than Variant Much faster than TValue (but slightly less powerfull)
18
Show me the code!
19
Danger, Will Robinson! “New programmers are drawn to multithreading like moths to flame, with similar results.” -Danny Thorpe Image © Hammacher Schlemmer
20
Be Afraid Be very afraid! Designing parallel solutions is hard
Writing multithreaded code is hard Testing multicore apps is hard Debugging multithreading code is pure insanity Yes, next two slides are copied from the previous presentation. It’s just that I can’t repeat this often enough …
21
Keep in Mind Don’t parallelize everything
Don’t create thousands of threads Rethink the algorithm Prove the improvements Test, test and test
22
Q & A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.