HIGH-LEVEL MULTITHREADED PROGRAMMING [PART II] Primož Gabrijelčič BACKGROUND INFORMATION About Me • Primož Gabrijelčič • Programmer, consultant, writer, speaker – thedelphigeek.com – www.glagolite.si/delphi • Hacking multithreaded code since.

Download Report

Transcript HIGH-LEVEL MULTITHREADED PROGRAMMING [PART II] Primož Gabrijelčič BACKGROUND INFORMATION About Me • Primož Gabrijelčič • Programmer, consultant, writer, speaker – thedelphigeek.com – www.glagolite.si/delphi • Hacking multithreaded code since.

HIGH-LEVEL MULTITHREADED
PROGRAMMING [PART II]
Primož Gabrijelčič
BACKGROUND
INFORMATION
About Me
• Primož Gabrijelčič
• Programmer, consultant, writer, speaker
– thedelphigeek.com
– www.glagolite.si/delphi
• Hacking multithreaded code since 1999
About OmniThreadLibrary
• „VCL for multithreading“
• Delphi 2007 – XE3[4]
• Open source – OpenBSD license
– www.omnithreadlibrary.com
– omnithreadlibrary.googlecode.com
• Win32/Win64
About the Webinars
• Code and video:
www.omnithreadlibrary.com/webinars
• Code = free, video = $10
• 20 free books, courtesy of the De Novo
Software, www.denovosoftware.com
High-Level Abstractions
•
•
•
•
Async [/Await]
Future
Join
ForEach
•
•
•
•
ParallelTask
BackgroundWorker
ForkJoin
Pipeline
High-Level Abstractions
• ParallelTask
• Async [/Await]
• BackgroundWorker
• Future
• ForkJoin
• Join
Start multiple background tasks [and wait]
• ForEach
• Pipeline
Join
Join(code1,
code2, code3)
code1
code3
code2
High-Level Abstractions
• ParallelTask
• Async [/Await]
Start multiple copies of a single task
• Future
• Join
• ForEach
• BackgroundWorker
• ForkJoin
• Pipeline
ParallelTask
High-Level Abstractions
• ParallelTask
• Async [/Await]
• BackgroundWorker
• Future
Background request-processing service
• Join
• ForEach
• ForkJoin
• Pipeline
Background Worker
BackgroundWorker Usage
• service := Paralell.BackgroundWorker.
OnRequestDone(code1).Execute(code2);
• workItem := service.CreateWorkItem(data);
• service.Schedule(workItem)
• service.Terminate; service := nil;
High-Level Abstractions
• Async [/Await]
• Future
• Join
• ParallelTask
• BackgroundWorker
• ForkJoin
Divide and conquer
• ForEach
• Pipeline
Fork/Join
Fork/Join Usage
• computation := Parallel.ForkJoin;
• compute1 := computation.Compute(action);
– Inside action: computation.Compute(newAction)
• compute2 := computation.Compute(action);
• compute1.Value / compute1.Await
• compute2.Value / compute2.Await
PARTING NOTES
Keep in Mind
•
•
•
•
•
Don’t parallelize everything
Rethink the algorithm
Data flow dictates the abstraction
Measure the improvements
Test, test and test
Code & Video
• Will be available shortly at
www.omnithreadlibrary.com/webinars