An overview of… Luis Guerrero Plain Concepts
-
Upload
morgan-hudman -
Category
Documents
-
view
215 -
download
0
Transcript of An overview of… Luis Guerrero Plain Concepts
Concurrent programming and MEF
An overview of…
Luis GuerreroPlain Conceptshttp://www.luisguerrero.nethttp://geeks.ms/blogs/luisguerrero/
Parallel Programing in the .NET Framework
Why?
Searching for Parallelism
Finding exploitable parallelism Organizing by Tasks Organizing by Data Organizing by Ordering
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
{}
{}
{}
{}
Organizing by Tasks
Work per task? Small workloads Variable workloads
Dependencies between tasks? Removable Separable Read only or read/write
{}
{}
{}
{}
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
{}
{}
{}
Patterns for Parallelism
Implementation Patterns Fork / Join Loop Parallel Divide and Conquer Producer / Consumer Pipeline Asynchronous Agents
What’s about this talk?
Task Parallel Library Parallel LINQ (PLINQ) Data Structures for Parallel
Programming Parallel Diagnostic Tools
Task Parallel Library - Overview
Data parallelism: The Parallel Class Parallel
For For<> Foreach Invoke
demoParallel class
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
demoCreating Tasks
demoTask continuation
demoExceptions and cancellation support
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.
demoBarrier y CountdownEvent
demoPLINQ
Managed Extensibility Framework (MEF)
An introduction to….
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
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
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.
Open/Closed Principle
Software entities should be open for extension, but closed for modification.
Known Unknown
VS.
MEF Basics…
An Application is built of parts.
MEF Basics…
Export it.
Import it.
Compose it.
Export it.
Widget1
[Export(typeof(UserControl))]public class Widget1 : UserControl{
public string Message { get{return(string) Button.Content;}
set{Button.Content=value;} }}
Export
UserControl
Import it.
Widget1
[Export(typeof(UserControl))]public class Widget1 : UserControl{
[Import]public string Message { get{return(string) Button.Content;}
set{Button.Content=value;} }}
Import
String
Import it.
Widget1
[Export(typeof(UserControl))]public class Widget1 : UserControl{
[Import(“HelloMEF.Message”)]public string Message { get{return(string) Button.Content;}
set{Button.Content=value;} }}
Import
“HelloMEF.Message”
Import it.
MainPage
[Export(typeof(UserControl))]public class MainPage: UserControl{
[ImportMany(typeof(UserControl))]public IEnumerable<UserControl> { get;set;}
}
ImportMany
UserControl
Compose it.PartIntializer: “Compose
yourself”
MainPage Compose
public MainPage() { InitializeComponent(); PartInitializer.SatisfyImports(this); }
Widget
Widget
Where does the widget
go?
Export it - Metadata
Widget1
[ExportMetadata(“Location”,Location.Top)][Export(typeof(UserControl))]public class Widget1 : UserControl{
public string Message { get{return(string) Button.Content;}
set{Button.Content=value;} }}
Export
UserControl
Put me in the top
Import it - Metadata
MainPage
[Export(typeof(UserControl))]public class MainPage: UserControl{
[ImportMany(typeof(UserControl))]public IEnumerable<Lazy<UserControl, IWidgetMetadata> { get;set;}
}
ImportMany
UserControl
Export it - Metadata
Widget1
[ExportMetadata(“Location”,Location.Top)][Export(typeof(UserControl))]public class Widget1 : UserControl{
public string Message { get{return(string) Button.Content;}
set{Button.Content=value;} }}
Export
UserControl
Put me in the top
Customize it – Custom exports
Widget1
[Widget(Location=Location.Top)]public class Widget1 : UserControl{
public string Message { get{return(string) Button.Content;}
set{Button.Content=value;} }}
Export
UserControl
Put me in the top
Container is the Match Maker
Container
Catalogs provide PartsContainer
Catalog
Catalogs provide PartsContainer
Catalog
TypeCatalog
AssemblyCatalog
DirectoryCatalog
AggregatingCatalog
Parts can be lazy…
Part B
Export<A>
[Import(typeof(ILogger))]public ILogger Export<ILogger> Logger { get; set; }
Lifetime
ContainerContainer
Part A Part B Part B Part B
[CompositionOptions(CreationPolicy=CreationPolicy.NonShared)][CompositionOptions(CreationPolicy=CreationPolicy.Shared)]
Shared Non-Shared
On Export
[Import(RequiredCreationPolicy=CreationPolicy.NonShared)][Import(RequiredCreationPolicy=CreationPolicy.Shared)]
On Import