Download presentation
Presentation is loading. Please wait.
Published bySergio Lapsley Modified over 9 years ago
2
System.Threading.Tasks Task Represents an asynchronous operation Supports waiting, cancellation, continuations, … Parent/child relationships 1 st -class debugging support in Visual Studio 2010 Task : Task Tasks that return results Task Exceptions Task Scheduler
3
In the year 2003, CPU performance growth had hit a wall. Up until then, most of us wrote sequential code and relayed on the CPU frequency to consistently raise (in 12 years it climbed from 400Hz to 3.8GHz) while futilely counting on Moore law (that the number of transistors on a chip will double about every two years) to keep on translating into faster processorsMoore law
4
More than 1 billion transistors in 2006! More than 1 billion transistors in 2006! The number of transistors doubles every two years… http://upload.wikimedia.org/wikipedia/commons/2/25/Transistor_Count_and_Moore%27s_Law_-_2008_1024.png
5
The number of transistors on Intel’s chips never stopped climbing, even after the year 2010. However, clock speed stopped on 2003 somewhere near 3GHz.
6
Frequencies will NOT get much faster! Maybe 5 to 10% every year or so, a few more times… And these modest gains would make the chips A LOT hotter! http://www.tomshw.it/cpu.php?guide=20051121
8
IEnumerable drivers =...; var results = new List (); foreach(var driver in drivers) { if (driver.Name == queryName && driver.Wins.Count >= queryWinCount) { results.Add(driver); } results.Sort((b1, b2) => b1.Age.CompareTo(b2.Age));
9
IEnumerable drivers = …; var results = new List (); int partitionsCount = Environment.ProcessorCount; int remainingCount = partitionsCount; var enumerator = drivers.GetEnumerator(); try { using (var done = new ManualResetEvent(false)) { for(int i = 0; i < partitionsCount; i++) { ThreadPool.QueueUserWorkItem(delegate { while(true) { RaceCarDriver driver; lock (enumerator) { if (!enumerator.MoveNext()) break; driver = enumerator.Current; } if (driver.Name == queryName && driver.Wins.Count >= queryWinCount) { lock(results) results.Add(driver); } if (Interlocked.Decrement(ref remainingCount) == 0) done.Set(); }); } done.WaitOne(); results.Sort((b1, b2) => b1.Age.CompareTo(b2.Age)); } finally { if (enumerator is IDisposable) ((IDisposable)enumerator).Dispose(); }
10
Global Queue Program Thread Worker Thread 1 Item 1 Item 2 Item 3 Item 4 Item 5 Item 6
11
Program Thread Lock-Free Global Queue Lock-Free Global Queue Local Work- Stealing Queue Local Work- Stealing Queue Local Work- Stealing Queue Worker Thread 1 Worker Thread p Task 1 Task 2 Task 3 Task 5 Task 4 Task 6
12
Parallel Pattern Library Resource Manager Task Scheduler Task Parallel Library Task Parallel Library Parallel LINQ Managed Native Key: Threads Operating System Concurrency Runtime Programming Models ThreadPool Task Scheduler Resource Manager Data Structures Tools Tooling Parallel Debugger Tool Windows Parallel Debugger Tool Windows Profiler Concurrency Analysis Profiler Concurrency Analysis Agents Library UMS Threads.NET Framework 4 Visual C++ 10 Visual Studio IDE Visual Studio IDE Windows
26
Theoretical maximum speedup determined by amount of sequential code
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.