1 / 41

Concurrent programming and MEF

An overview of…. Concurrent programming and MEF. Luis Guerrero Plain Concepts http://www.luisguerrero.net http://geeks.ms/blogs/luisguerrero/. Parallel Programing in the .NET Framework. Why?. Searching for Parallelism. Finding exploitable parallelism Organizing by Tasks

Download Presentation

Concurrent programming and MEF

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An overview of… Concurrent programming and MEF Luis Guerrero Plain Concepts http://www.luisguerrero.net http://geeks.ms/blogs/luisguerrero/

  2. Parallel Programing in the .NET Framework

  3. Why?

  4. Searching for Parallelism • Finding exploitable parallelism • Organizing by Tasks • Organizing by Data • Organizing by Ordering

  5. Organizing by Tasks • Linear or recursive? • Task parallel • Divide and conquer • Enough task? • Too many – thrashing • Too few – under utilization • Dependencies between tasks • Scheduling work to tasks

  6. Organizing by Tasks • Work per task? • Small workloads • Variable workloads • Dependencies between tasks? • Removable • Separable • Read only or read/write

  7. Organizing by Data • Linear or recursive? • Geometric decomposition • Recursive data • Data “chunk” size? • Too big – under utilization • Too small – trashing • Chunk layout? • Cache and cache line size • False cache sharing

  8. Patterns for Parallelism • Implementation Patterns • Fork / Join • Loop Parallel • Divide and Conquer • Producer / Consumer • Pipeline • Asynchronous Agents

  9. What’s about this talk? • Task Parallel Library • Parallel LINQ (PLINQ) • Data Structures for Parallel Programming • Parallel Diagnostic Tools

  10. Task Parallel Library - Overview • Data parallelism: The Parallel Class • Parallel • For • For<> • Foreach • Invoke

  11. Parallel class demo

  12. Task – Overview • Task is the minimum unit of work in TPL • Can be scheduled by request • 2 Scheduled inside .NET box, ThreadPool y UI • Can have a result • Is observable • Can be continue with another task • Can be securely cancelled • Someone can wait for a completion

  13. Creating Tasks demo

  14. Task continuation demo

  15. Exceptions and cancellation support demo

  16. New System.Threading Primitives A Barrier is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point. A CountdownEvent is a synchronization primitive that enables ongoing tracking of a given workload in order to determine if processing of that workload is finished or not.

  17. Barrier y CountdownEvent demo

  18. PLINQ demo

  19. An introduction to…. Managed Extensibility Framework (MEF)

  20. Managed Extensibility Framework The Managed Extensibility Framework (MEF) is a new library in .NET 4 for building applications that can be incrementally extended. • For customers • For you and your team • Always there, always ready

  21. Managed Extensibility Framework? The Managed Extensibility Framework (MEF) is a new library in the .NET Framework that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed

  22. What is “Extensibility”? In software engineering, extensibility is a systemic measure of the ability to extend a system and the level of effort required to implement the extension.

  23. Open/Closed Principle Software entities should be open for extension, but closed for modification.

  24. VS. Known Unknown

  25. MEF Basics… • An Application is built of parts.

  26. MEF Basics… • Export it. • Import it. • Compose it.

  27. Export it. [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 UserControl Export

  28. Import it. [Export(typeof(UserControl))] public class Widget1 : UserControl { [Import] public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 String Import

  29. Import it. [Export(typeof(UserControl))] public class Widget1 : UserControl { [Import(“HelloMEF.Message”)] public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 “HelloMEF.Message” Import

  30. Import it. [Export(typeof(UserControl))] public class MainPage: UserControl { [ImportMany(typeof(UserControl))] public IEnumerable<UserControl> { get;set; } } Main Page UserControl ImportMany

  31. Compose it. PartIntializer: “Compose yourself” public MainPage() { InitializeComponent(); PartInitializer.SatisfyImports(this); } MainPage Compose

  32. Where does the widget go? Widget Widget

  33. Export it - Metadata [ExportMetadata(“Location”,Location.Top)] [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 Put me in the top UserControl Export

  34. Import it - Metadata [Export(typeof(UserControl))] public class MainPage: UserControl { [ImportMany(typeof(UserControl))] public IEnumerable<Lazy<UserControl, IWidgetMetadata> { get;set; } } Main Page UserControl ImportMany

  35. Export it - Metadata [ExportMetadata(“Location”,Location.Top)] [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 Put me in the top UserControl Export

  36. Customize it – Custom exports [Widget(Location=Location.Top)] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 Put me in the top UserControl Export

  37. Container is the Match Maker Container

  38. Catalogs provide Parts Container Catalog

  39. Catalogs provide Parts TypeCatalog Container AssemblyCatalog DirectoryCatalog Catalog AggregatingCatalog

  40. Parts can be lazy… [Import(typeof(ILogger))] public ILoggerExport<ILogger> Logger { get; set; } Part B Export <A>

  41. Lifetime On Export [CompositionOptions(CreationPolicy=CreationPolicy.NonShared)] [CompositionOptions(CreationPolicy=CreationPolicy.Shared)] On Import [Import(RequiredCreationPolicy=CreationPolicy.NonShared)] [Import(RequiredCreationPolicy=CreationPolicy.Shared)] Shared Non-Shared Container Container Part A Part B Part B Part B

More Related