3. MANYCORE SHIFT
Despite Moore’s Law, manufacturers have hit a practical limit
for single core processors
• Smaller transistors are more prone to “leak”
• Faster clock speeds require more power, which produces
more heat
Instead of making one strong processor, make smaller
parallel processors
4. INTRODUCING PARALLEL
EXTENSIONS
aka Task Parallel Library (TPL)
First CTP’d November 30th, 2007
Added to .NET 4.0
Easy way to take advantage of multi-core parallel processing
in applications while abstracting out thread management and
scheduling
5. THREADS
Thread t = new Thread(ThreadStart)
Common Scenarios:
• Long running queries against a data layer
• Disk / Network IO
• Separate blocking operations from the UI thread
Hiding latency, adding perceived performance
No actual performance gain
No automatic management of thread execution
• Leading to context switching, invalidating cache, extra
memory usage
8. BACKGROUND WORKER
Basically a wrapper for ThreadPool
Provides hooks to report progress
(ProgressChanged), report completion
(RunWorkerCompleted), and supports cancellation
(CancellationPending)
Could do all the same stuff with a ThreadPool, but this wires
it up for you
9. TASKS
Task t = new Task(Action)
Similar to ThreadPool – uses a delegate, queue’d
But provides hooks into and across tasks:
t.Wait() / Task.WaitAll(t, t2, …) – allows main thread to wait for
task completion
t.ContinueWith(new Task()) – specifies a task should start
after another task completes
t.Cancel() – cancel any running task
t = new Task<int>() – return an int value from the task to the
executing thread
11. PLINQ
Collection.AsParallel()
LINQ version of Parallel Extensions
ParallelQuery and ParallelEnumerable
Collection.AsParallel().Where(x => x.IsPrime())
Can specify cancellation conditions, degree of
parallelism, buffering options
12. OLD STUFF
Async, Await keywords in .NET 5.0 (VB and C#)
string DownloadJson(string url)
{
Console.WriteLine(“Fetching JSON”);
WebClient client = new WebClient();
client.DownloadStringCompleted += (result) => {
Console.WriteLine(“JSON: “ + result);
return result;
}
client.DownloadStringAsync(url);
}
15. NEW STUFF, FLOWCHARTED
Main Thread
DownloadJson(url) delegate(result)
OnCompleted
Call DownloadJson
await WebClient.DownloadStringTaskAsync
16. MORE NEW STUFF
DataFlow
Uses “blocks” to perform operations
var ab = ActionBlock<int>((i) => { Console.WriteLine(i.ToString(“c”); });
ab.Post(4);
var tb = TransformBlock<int, int>((i) => { return i * 3; });
tb.LinkTo(ab);
tb.Post(6);
Hinweis der Redaktion
Been with iQ for about 5 yearsWorked in the Regina office until the last two years when I moved to VancouverWorking primarily on web projects, but have done a few RetailiQ v3 projectsCreated the RQ4 WPF prototypeCurrently work on XQ Console