SlideShare a Scribd company logo
1 of 57
Download to read offline
@gfraiteur
Surmounting complexity by raising abstraction
Multithreading Design Patterns
Gaël Fraiteur
PostSharp Technologies
Founder & Principal Engineer
@gfraiteur
Hello!
My name is GAEL.
No, I don’t think
my accent is funny.
my twitter
@gfraiteur
My commitment to you:
to seed a vision, not to sell a tool.
@gfraiteur
The vision:
Code at the right level of abstraction,
with compiler-supported design patterns
@gfraiteur
back in
1951
@gfraiteur
hardware was fun
but quite simple to use
@gfraiteur
Univac Assembly Language
@gfraiteur
FORTRAN (1955)
• 1955 - FORTRAN I
• Global Variables
• Arrays
• 1958 - FORTRAN II
• Procedural Programming
(no recursion)
• Modules
@gfraiteur
COBOL (1959)
• Data Structures
@gfraiteur
LISP (1959)
• Variable Scopes (Stack)
• Garbage Collection
@gfraiteur
The new invention caught quickly, no wonder, programs
computing nuclear power reactor parameters took now
HOURS INSTEAD OF WEEKS
to write, and required much
LESS PROGRAMMING SKILL
@gfraiteur
1. The Memory Management Revolution
2. Models and Patterns
3. Defining Threading Models
4. Designing with Threading Models
5. A Few Threading Models
6. Q&A
7. Summary
Section
@gfraiteur
How do programming languages
increase productivity?
@gfraiteur
What you
may think
the compiler
does for you.
Code Validation
Instruction Generation
@gfraiteur
Compilers translate code
FROM HIGH
TO LOW ABSTRACTION language
@gfraiteur
Languages let us express
ourselves against a model
Thing Concept Word
Model Language
∞ 1
World
abstracted into expressed with
∞ ∞
1 1
∞
1
1 1
abstracted into expressed with
@gfraiteur
Good Models are Easy
• Allow for succinct expression of intent (semantics), with less
focus on implementation details
• less work
• fewer things to think about
• Allow for extensive validation of source code against the model
• early detection of errors
• Allow for better locality and separation of concerns
• “everything is related to everything” no more
• Are deterministic
• no random error
@gfraiteur
Good Models are Friendly
• to human mind structure
• cope with limited human cognitive abilities
• to social organization
• cope with skillset differences, division of labor,
time dimension, changes in requirements
@gfraiteur
The Classic Programming Model
Quality Realization
Succinct semantics • Concept of subroutine
• Unified concept of variable
(global, local, parameters, fields)
Validation • Syntactic (spelling)
• Semantic (type analysis)
• Advanced (data flow analysis)
Locality • Information hiding (member visibility)
• Modularity
Determinism • Total (uninterrupted single-threaded program)
@gfraiteur
1. The Memory Management Revolution
2. Models and Patterns
3.Defining Threading Models
4. Designing with Threading Models
5. A Few Threading Models
6. Q&A
7. Summary
Section
@gfraiteur
Why we need threading models
• Multithreading is way too hard – today
• Too many things to think about
• Too many side effects
• Random data races
• Your colleagues won’t get smarter
• Increased demand – end of free lunch
@gfraiteur
@gfraiteur
The Root of All Evil
Access to Shared Mutable State
• Memory ordering
• Atomicity / transactions
• Typical damage: data races
• Corruption of data structures
• Invalid states
@gfraiteur
Locks alone are
not the solution
@gfraiteur
@gfraiteur
Locks alone are
not the solution
• Easy to forget
• Difficult to test
• Deadlocks
@gfraiteur
"Problems cannot be solved by
the same level of thinking that
created them."
(and you’re not a man if you haven’t cited Albert Einstein)
@gfraiteur
Threading Models
Reader-Writer
Sync’ed
Pessimistic
Transactions
Lock-Based
Lock-Free
Optimistic
Transactions
Transactional
Avoid Mutable State
Thread Exclusive
Immutable
Actor
Avoid Shared Mutable State
Avoid Shared State
@gfraiteur
• Named solution
• Best practice
• Documented
• Abstraction
• Automation
• Validation
• Determinism
Threading Models are…
Models Design Patterns
@gfraiteur
1. The Memory Management Revolution
2. Models and Patterns
3. Defining Threading Models
4.Designing with Threading Models
5. A Few Threading Models
6. Q&A
7. Summary
Section
@gfraiteur
Golden rule: all shared state must be thread-safe.
@gfraiteur
Assign threading models
to types
1. Every class must be assigned a threading model.
2. Define aggregates with appropriate granularity.
1.
@gfraiteur
Product
Invoice
Party
Store
Invoice InvoiceLine
Product
-lines
1
-invoice
*
-product *
1
Party
-invoices1
-customer*
ProductPart-parts
1
-product
*
Address
-addresses
1*
StockItem
Store
-items 1
-store *
*
-part1
reader-writer-
synchronized
reader-writer-
synchronizedreader-writer-
synchronized
actor
@gfraiteur
Ensure only thread-safe
types are shared
1. Arguments of cross-thread methods
2. All static fields must be read-only
and of thread-safe type.
2.
@gfraiteur
1. The Memory Management Revolution
2. Models and Patterns
3. Defining Threading Models
4. Designing with Threading Models
5. A Few Threading Models
6. Q&A
7. Summary
Section
@gfraiteur
Immutable Pattern
Never changed after creation.
Make a copy if you want to modify it.
Issue: multi-step object
initialization (e.g. deserialization)
@gfraiteur
Freezable Pattern
1. Implement interface IFreezable
Freeze() must propagate to
children objects.
2. Before any non-const method, throw exception if
object is frozen.
3. Call the Freeze method after any initialization.
@gfraiteur
Thread Exclusive
Promises never to be involved
with multithreading. Ever.
@gfraiteur
Thread Exclusivity Strategies
• Exclusivity Policies:
• Thread Affinity (e.g. GUI objects)
• Instance-Level Exclusivity (e.g. most .NET objects)
• Type-Level Exclusivity
• Concurrency Behavior:
• Fail with exception
• Wait with a lock
@gfraiteur
Implementing
Thread Affine Objects
• Remember current thread in constructor
• Verify current thread in any public method
• Prevent field access from outside current instance
• Only private/protected fields
• Only accessed in “this.field”
@gfraiteur
Implementing Thread Excluse
Objects
• Acquire lock before any public method
• Wait/throw if it cannot be acquired
• Prevent field access from outside current instance
• Only private/protected fields
• Only accessed in “this.field”
• Note: “Throw” behavior is non-deterministic
@gfraiteur
Stricter coding constraints increase code verifiability.
@gfraiteur
Lab:
Checking Thread Exclusivity
@gfraiteur
Actor Model
Bound to a single thread
(at a time)
@gfraiteur
Message
Queue
Private
Mutable
State
Single
Worker
Actors:
No Mutable
Shared State
@gfraiteur
Composing Actors
@gfraiteur
Actor Sequence Diagram
Object1 Object2 Object3
Request1 Request2
Response1
Response2
Wait in
message
queue
@gfraiteur
• with compiler support:
• Erlang,
• F# Mailbox
• PostSharp
• without compiler
support:
• NAct
• ActorFX
Actor implementations
@gfraiteur
Verifying the Actor Model
• Public methods will be made async
• Parameters and return values
of public methods must be thread-safe
• Methods with return value must be async
• Prevent field access from outside current instance
• Only private/protected fields
• Only accessed in “this.field”
@gfraiteur
Lab: Implementing Actors
@gfraiteur
• Performance
• Theoretical Latency: min 20 ns
(L3 double-trip)
• Practical throughput (ring
buffer): max 6 MT/s per core
• Difficult to write
without proper
compiler support
• Reentrance issues with
waiting points (await)
• Race free (no shared
mutable state)
• Lock free (no waiting,
no deadlock)
• Scales across processes,
machines
Actors
Benefits Limitations
@gfraiteur
Reader-Writer Synchronized
Everybody can read unless someone writes.
@gfraiteur
Reader-Writer Synchronized
• 1 lock per [group of] objects
• e.g. invoice and invoice lines share the same lock
• Most public methods require locks:
Method Required Lock Level
Reads 1 piece of state None
Reads 2 pieces of state Read
Writes 1 piece of state Write
Reads large amount of state,
then writes state
Upgradeable Read, then
Write
@gfraiteur
Lab: Implementing RWS
@gfraiteur
Transactions
• Isolate shared state into thread-specific storage
• Commit/Rollback semantics
• Platform ensures ACID properties:
• Atomicity, Consistency, Isolation, (Durability)
• Type of concurrency policies
• Pessimistic (lock-based: several “isolation levels”
available)
• Optimistic (lock-free, retry-based)
As far as I'm concerned, I prefer silent vice
to ostentatious virtue. Albert Einstein“
@gfraiteur
Q&A
Gael Fraiteur
gael@postsharp.net
@gfraiteur
@gfraiteur
Summary
• Repeat the memory management
success with the multicore issue.
• Models decrease complexity to
a cognitively bearable level.
• We need compilers that allow
us to use our own models
and patterns.
BETTER SOFTWARE THROUGH SIMPLER CODE

More Related Content

What's hot

[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트
[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트
[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트Atlassian 대한민국
 
Software Design Specification For Smart Internet Cafe
Software Design Specification For Smart Internet CafeSoftware Design Specification For Smart Internet Cafe
Software Design Specification For Smart Internet CafeHari
 
Online Shopping System Test case Writing
Online Shopping System Test case WritingOnline Shopping System Test case Writing
Online Shopping System Test case Writingchiragmakdiya
 
테스트자동화 성공전략
테스트자동화 성공전략테스트자동화 성공전략
테스트자동화 성공전략SangIn Choung
 
An overview of object oriented systems development
An overview of object oriented systems developmentAn overview of object oriented systems development
An overview of object oriented systems developmentAdri Jovin
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)WebStackAcademy
 
A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...
A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...
A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...Fatima Qayyum
 
Use case diagram
Use case diagramUse case diagram
Use case diagramAre-u
 
Uml Diagrams for Web Developers
Uml Diagrams for Web DevelopersUml Diagrams for Web Developers
Uml Diagrams for Web DevelopersDave Kelleher
 
Test Plan for online auction system
Test Plan for online auction systemTest Plan for online auction system
Test Plan for online auction systemKomalah Nair
 
Online shopping cart system file
Online shopping cart system fileOnline shopping cart system file
Online shopping cart system fileSunil Jaiswal
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case DiagramKumar
 
Ecommerce website with seo optimization
Ecommerce website with seo optimizationEcommerce website with seo optimization
Ecommerce website with seo optimizationKumar Narayan
 
Srs group 4 v5 - esmart shopping
Srs group 4  v5 - esmart shoppingSrs group 4  v5 - esmart shopping
Srs group 4 v5 - esmart shoppingadprojects1
 

What's hot (20)

inventory management system
 inventory management system inventory management system
inventory management system
 
[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트
[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트
[AIS 2018] [Team Tools_Basic] Jira Software를 활용하여 생산성을 높이기 - 모우소프트
 
Software Design Specification For Smart Internet Cafe
Software Design Specification For Smart Internet CafeSoftware Design Specification For Smart Internet Cafe
Software Design Specification For Smart Internet Cafe
 
Online Shopping System Test case Writing
Online Shopping System Test case WritingOnline Shopping System Test case Writing
Online Shopping System Test case Writing
 
테스트자동화 성공전략
테스트자동화 성공전략테스트자동화 성공전략
테스트자동화 성공전략
 
An overview of object oriented systems development
An overview of object oriented systems developmentAn overview of object oriented systems development
An overview of object oriented systems development
 
Unit 4
Unit 4Unit 4
Unit 4
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...
A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...
A Low-Cost IoT Application for the Urban Traffic of Vehicles, Based on Wirele...
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
 
Uml Diagrams for Web Developers
Uml Diagrams for Web DevelopersUml Diagrams for Web Developers
Uml Diagrams for Web Developers
 
Test Plan for online auction system
Test Plan for online auction systemTest Plan for online auction system
Test Plan for online auction system
 
Online shopping cart system file
Online shopping cart system fileOnline shopping cart system file
Online shopping cart system file
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Ecommerce website with seo optimization
Ecommerce website with seo optimizationEcommerce website with seo optimization
Ecommerce website with seo optimization
 
Unit 5
Unit 5Unit 5
Unit 5
 
Srs group 4 v5 - esmart shopping
Srs group 4  v5 - esmart shoppingSrs group 4  v5 - esmart shopping
Srs group 4 v5 - esmart shopping
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Java script basics
Java script basicsJava script basics
Java script basics
 

Similar to Multithreading Design Patterns

Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Fwdays
 
Industry - Program analysis and verification - Type-preserving Heap Profiler ...
Industry - Program analysis and verification - Type-preserving Heap Profiler ...Industry - Program analysis and verification - Type-preserving Heap Profiler ...
Industry - Program analysis and verification - Type-preserving Heap Profiler ...ICSM 2011
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Search at Twitter: Presented by Michael Busch, Twitter
Search at Twitter: Presented by Michael Busch, TwitterSearch at Twitter: Presented by Michael Busch, Twitter
Search at Twitter: Presented by Michael Busch, TwitterLucidworks
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Martijn Verburg
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Andrei KUCHARAVY
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in RubyThoughtWorks
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in RubyThoughtWorks
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioMuralidharan Deenathayalan
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioMuralidharan Deenathayalan
 
Data Science Accelerator Program
Data Science Accelerator ProgramData Science Accelerator Program
Data Science Accelerator ProgramGoDataDriven
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPrashant Rane
 
Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever CodeGabor Varadi
 
TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...
TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...
TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...chiportal
 
Fault tolerance - look, it's simple!
Fault tolerance - look, it's simple!Fault tolerance - look, it's simple!
Fault tolerance - look, it's simple!Izzet Mustafaiev
 
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...Gerke Max Preussner
 

Similar to Multithreading Design Patterns (20)

Design Pattern Automation
Design Pattern AutomationDesign Pattern Automation
Design Pattern Automation
 
Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
Multithreading Fundamentals
Multithreading FundamentalsMultithreading Fundamentals
Multithreading Fundamentals
 
Industry - Program analysis and verification - Type-preserving Heap Profiler ...
Industry - Program analysis and verification - Type-preserving Heap Profiler ...Industry - Program analysis and verification - Type-preserving Heap Profiler ...
Industry - Program analysis and verification - Type-preserving Heap Profiler ...
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Search at Twitter: Presented by Michael Busch, Twitter
Search at Twitter: Presented by Michael Busch, TwitterSearch at Twitter: Presented by Michael Busch, Twitter
Search at Twitter: Presented by Michael Busch, Twitter
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Data Science Accelerator Program
Data Science Accelerator ProgramData Science Accelerator Program
Data Science Accelerator Program
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
 
Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever Code
 
TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...
TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...
TRACK F: OpenCL for ALTERA FPGAs, Accelerating performance and design product...
 
Fault tolerance - look, it's simple!
Fault tolerance - look, it's simple!Fault tolerance - look, it's simple!
Fault tolerance - look, it's simple!
 
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
 

More from PostSharp Technologies

Advanced Defensive Coding Techniques (with Introduction to Design by Contract)
Advanced Defensive Coding Techniques (with Introduction to Design by Contract)Advanced Defensive Coding Techniques (with Introduction to Design by Contract)
Advanced Defensive Coding Techniques (with Introduction to Design by Contract)PostSharp Technologies
 
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain ModelsApplying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain ModelsPostSharp Technologies
 
Building Better Architecture with UX-Driven Design
Building Better Architecture with UX-Driven DesignBuilding Better Architecture with UX-Driven Design
Building Better Architecture with UX-Driven DesignPostSharp Technologies
 
Solving Localization Challenges with Design Pattern Automation
Solving Localization Challenges with Design Pattern AutomationSolving Localization Challenges with Design Pattern Automation
Solving Localization Challenges with Design Pattern AutomationPostSharp Technologies
 
Applying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformancePostSharp Technologies
 
10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware ProgrammingPostSharp Technologies
 
Produce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingProduce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingPostSharp Technologies
 

More from PostSharp Technologies (8)

Advanced Defensive Coding Techniques (with Introduction to Design by Contract)
Advanced Defensive Coding Techniques (with Introduction to Design by Contract)Advanced Defensive Coding Techniques (with Introduction to Design by Contract)
Advanced Defensive Coding Techniques (with Introduction to Design by Contract)
 
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain ModelsApplying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
 
Performance is a Feature!
Performance is a Feature!Performance is a Feature!
Performance is a Feature!
 
Building Better Architecture with UX-Driven Design
Building Better Architecture with UX-Driven DesignBuilding Better Architecture with UX-Driven Design
Building Better Architecture with UX-Driven Design
 
Solving Localization Challenges with Design Pattern Automation
Solving Localization Challenges with Design Pattern AutomationSolving Localization Challenges with Design Pattern Automation
Solving Localization Challenges with Design Pattern Automation
 
Applying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website Performance
 
10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming
 
Produce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingProduce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented Programming
 

Recently uploaded

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 

Recently uploaded (20)

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 

Multithreading Design Patterns

Editor's Notes

  1. Good morning! My name is Gael Fraiteur. If you think I have a weird accent and even think I am French, but actually I was grown in Belgium and have lived in Czech Republic for the last 12 years.I have been programming non-stop since age of 11, building my first useful program at 12 – it was still reported in use when I got married. My father has been involved with IT in most of his career and my grandfather was probably one of the first programmers in Belgium.(connect to the audience)My grandfather had a PhD in meteorology. He was involved in early weather prediction computing. It’s always fun to talk with him about these heroic times of computing. By far, the rarest resource was working memory (RAM). They had just a few kilobytes of it, and it has to contain the data and the program. Of course they wrote their code in assembly because the single very optimization was importance.Also, they were moving data between RAM and disk back and forth. Of course we’re still doing that when we need to work with dataset that exceed a few GBs. But even doing that was not enough to keep under the 4KB limit, so they also dynamically loaded and unloaded parts of the program – just to save a few hundred bytes. We’re still doing that today but this is transparent to the application programmer thanks to the concept of virtual memory. Virtual memory is an abstraction layer that hides implementation details. There are other abstraction layers: the operating system, the CLR, the programming languages, and the frameworks. All these layers ultimately allow us to write code at a high level of abstraction, without bothering of implementation details.So, there has been this amazing evolution in sixty years. Most of us here are the third generation of programmers. Our predecessors did a marvelous job. What are our today’s challenges and what will be our contribution? Twenty years from now, will our successors laugh at us, consider our current programming languages as mere evolutions of the assembly language, and most of our code as technical wiring that will then be done automatically by “the machine”? I hope so, I hope our generation will be able to make a difference.Today’s challenge is no longer scarce resources, but multithreading. I think this is the number-one problem that our generation needs to tackle. And I think we should get inspiration from our predecessors: how did they succeed with the memory management problem? What are the lessons we can apply today? In this talk, I will argue that we should once again raise the level of abstraction and, this time, we should investigate how programming languages and compilers could allow for a better use of design patterns – or threading models, in this case.Nine years ago, I started working on an open-source project named PostSharp. Essentially, PostSharp allows developers to write custom attributes that extend the language, because PostSharp post-processes the compiler’s output at build time. Most examples in this talk are written in PostSharp, but this talk is more conceptual than practical, so examples are not a big deal of it.
  2. Three years ago, PostSharp outgrew my capacity to maintain it as a free open-source project and, out of necessity, became a commercial product. In an industry dominated by open source and big platform vendors, to make a living from development tools is extraordinarily difficult. We at PostSharp Technologies have been fortunate enough to succeed in this endeavor. We are grateful for the trust we receive from our customers – from the one-man shop to the largest corporations.This remark should also serve as a disclaimer that this talk shall undoubted be biased by my very source of revenues.However, my commitment to you in this talk is to share the vision which motivates us day after day. This vision is much larger than our product itself, and you can implement it with other tools, perhaps less appropriate – and, hopefully we will be able to spark an idea that will influence the design of future language and compilers.
  3. UNIVAC1 control station
  4. Mercury delay line memory of UNIVAC 1 (1951)  approx. 13 KBhttp://univac1.0catch.com/#b218 channels, each 10 words of 12 6-bit characters http://en.wikipedia.org/wiki/File:Mercury_memory.jpg
  5. Programming for the UNIVAC FAC-TRONIC system, 1935 by Remington Rand inchttp://bitsavers.informatik.uni-stuttgart.de/pdf/univac/univac1/UNIVAC_Programming_Jan53.pdf
  6. http://en.wikipedia.org/wiki/File:FortranCardPROJ039.agr.jpg
  7. LISP 1.5 Programmer’s Manual
  8. http://www.ibiblio.org/pub/languages/fortran/ch1-1.html20x less statements than assembly
  9. http://blog.superfeedr.com/ruby/open/ruby-fibers-may-confuse/
  10. http://www.thefreewallpapers.com/wp-content/uploads/2011/06/Tree-in-nature.jpgNow that even mobile phones have multiple cores, it is no longer original to repeat that the free lunch is over and that software developers must embrace multithreaded programming. Although this is much more complex than single-threaded programming, there’s little chance that software developers are going to get smarter – I mean that our cognitive abilities are not likely to increase so much. Investments in training and other skill improvement are necessary but are not going to bring the order-of-magnitude improvement we need to face tomorrow’s growing challenge. Instead, I believe we should focus breaking down complexity – that is, to it easier to write good software.The software industry faced a similar challenge sixty years ago with memory management, and we should look at how our predecessors tackled the problem. What they did is to define a memory model that was close to the way we humans think, and to build compiler to translate code expressed against this model into code that can be executed by the machine. That is, the first programming languages addressed complexity by raising the abstraction level. We need to repeat this success with multithreading. That is, we need to be able to build code against threading models (or threading patterns), and the compiler or runtime environment should be smart enough to perform deterministic validation of our code.Moreover, I think we need compilers that allow us to define our own models and design patterns. Not only for multithreading, but for any other concern. In an ideal world, humans should tell the machines what needs to be done and not how to do it. In an ideal world, source code should not be significantly more difficult or larger than the description of a solution in natural language.With PostSharp, we are proud to contribute to this v