SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
Threads - Why Can't You
Just Play Nicely With Your
Memory?
many cores with java
session three
two cores
copyright 2013 Robert Burrell Donkin robertburrelldonkin.name
this work is licensed under a Creative Commons Attribution 3.0 Unported License
Pre-emptive multi-tasking operating
systems use involuntary context
switching to provide the illusion of
parallel processes even when the
hardware supports only a single thread
of execution.
Take Away from Session One
Even on a single core,
there's no escaping parallelism.
Take Away from Session Two
Two Cores on One Chip
● Share caches
○ not L1
○ perhaps L2
○ probably L3
● Communicate fast and fat
○ in comparison to IO: very fast
○ in comparison to memory: fast
○ in comparison to intra-core: slow
● Cache consistency is cheap(er)
Two Cores on Two Chip
● No share caches
○ not L1
○ not L2
○ not L3
○ share only main memory
● Communicate maybe...?
○ in comparison to IO: fast
○ in comparison to memory: so-so
○ in comparison to intra-core: very slow
● Consistency is expensive
When Memory is Shared
● Until memory is shared
○ compiler,
○ hardware and
○ operating system
○ sweep the messy details under the rug
● When memory is shared
○ the software platform
○ guarantees reasonable behaviour
○ when code plays by the rules
Some Software Strategies
● Applicable to any shared resource
○ but memory as an example is
■ convenient and
■ common
● Mutual exclusion
○ no concurrent access to critical sections
● Non-blocking algorithms
○ CAS - compare and swap
Locks
● Block threads
○ which do not hold the lock
○ from a critical section
● When thread holding the lock
○ exits the critical section
○ other threads may no longer be blocked
Reading Stale Data
● Recall
○ that caches are not always coherent
○ two cores and main memory may not agree about a
value for a memory location
● Mutual exclusion is often not enough
○ memory barrier needed
○ hardware ensures data is coherent
○ expensive
● In Java, synchronized
○ locks and
○ issues memory barrier
● Several ways to implement in hardware
● When writing a value:
○ send expected existing value
○ return actual existing value on failure
● Step along the road to transactional memory
○ Similar to optimistic locking in an RDBMS
CAS - Compare and Swap
Take Away
Code executing on different cores uses copies
held in registers and caches, so memory
shared is likely to be incoherent unless the
program plays by the rules of the software
platform.

Contenu connexe

Tendances

Parallel programming
Parallel programmingParallel programming
Parallel programming
Swain Loda
 
Aleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_DevelopmentAleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_Development
Ciklum
 
what every web and app developer should know about multithreading
what every web and app developer should know about multithreadingwhat every web and app developer should know about multithreading
what every web and app developer should know about multithreading
Ilya Haykinson
 

Tendances (20)

Lecture2
Lecture2Lecture2
Lecture2
 
NUMA and Java Databases
NUMA and Java DatabasesNUMA and Java Databases
NUMA and Java Databases
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
PromptWorks Talk Tuesdays: Ray Zane 9/13/16 "Elixir Processes"
PromptWorks Talk Tuesdays: Ray Zane 9/13/16 "Elixir Processes"PromptWorks Talk Tuesdays: Ray Zane 9/13/16 "Elixir Processes"
PromptWorks Talk Tuesdays: Ray Zane 9/13/16 "Elixir Processes"
 
Streams
StreamsStreams
Streams
 
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
Java one2015 - Work With Hundreds of Hot Terabytes in JVMsJava one2015 - Work With Hundreds of Hot Terabytes in JVMs
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
 
Snooping protocols 3
Snooping protocols 3Snooping protocols 3
Snooping protocols 3
 
Cache coherence ppt
Cache coherence pptCache coherence ppt
Cache coherence ppt
 
Nano-node: Intelligent Hard Drives in Large Storage Infrastructures
Nano-node: Intelligent Hard Drives in Large Storage InfrastructuresNano-node: Intelligent Hard Drives in Large Storage Infrastructures
Nano-node: Intelligent Hard Drives in Large Storage Infrastructures
 
Thread
ThreadThread
Thread
 
Thread
ThreadThread
Thread
 
Parallel programming
Parallel programmingParallel programming
Parallel programming
 
Mongodb meetup
Mongodb meetupMongodb meetup
Mongodb meetup
 
Thread presentation
Thread presentationThread presentation
Thread presentation
 
Aleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_DevelopmentAleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_Development
 
Freckle
FreckleFreckle
Freckle
 
SYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSINGSYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSING
 
Mesi
MesiMesi
Mesi
 
Long Term Road Test of C*
Long Term Road Test of C*Long Term Road Test of C*
Long Term Road Test of C*
 
what every web and app developer should know about multithreading
what every web and app developer should know about multithreadingwhat every web and app developer should know about multithreading
what every web and app developer should know about multithreading
 

En vedette (8)

6 chicagotribune-gen-paris
6   chicagotribune-gen-paris6   chicagotribune-gen-paris
6 chicagotribune-gen-paris
 
Create a Social Media Strategy for your Business
Create a Social Media Strategy for your Business Create a Social Media Strategy for your Business
Create a Social Media Strategy for your Business
 
Sold! Event - May 24, 2011
Sold! Event - May 24, 2011 Sold! Event - May 24, 2011
Sold! Event - May 24, 2011
 
MSTA Change Agent Conference - Standards Based Grading
MSTA Change Agent Conference - Standards Based GradingMSTA Change Agent Conference - Standards Based Grading
MSTA Change Agent Conference - Standards Based Grading
 
G I N Dec08
G I N  Dec08G I N  Dec08
G I N Dec08
 
Chiou
ChiouChiou
Chiou
 
Audience research
Audience researchAudience research
Audience research
 
Edits for the development
Edits for the developmentEdits for the development
Edits for the development
 

Similaire à Threads - Why Can't You Just Play Nicely With Your Memory?

Introduction to Memoria
Introduction to MemoriaIntroduction to Memoria
Introduction to Memoria
Victor Smirnov
 
Introduction to multi core
Introduction to multi coreIntroduction to multi core
Introduction to multi core
mukul bhardwaj
 

Similaire à Threads - Why Can't You Just Play Nicely With Your Memory? (20)

Threads and processes
Threads and processesThreads and processes
Threads and processes
 
An End to Order (many cores with java, session two)
An End to Order (many cores with java, session two)An End to Order (many cores with java, session two)
An End to Order (many cores with java, session two)
 
An End to Order
An End to OrderAn End to Order
An End to Order
 
Java under the hood
Java under the hoodJava under the hood
Java under the hood
 
Improvements in Bitsy 1.5
Improvements in Bitsy 1.5Improvements in Bitsy 1.5
Improvements in Bitsy 1.5
 
If the data cannot come to the algorithm...
If the data cannot come to the algorithm...If the data cannot come to the algorithm...
If the data cannot come to the algorithm...
 
SNIA SDC 2016 final
SNIA SDC 2016 finalSNIA SDC 2016 final
SNIA SDC 2016 final
 
Kafka on ZFS: Better Living Through Filesystems
Kafka on ZFS: Better Living Through Filesystems Kafka on ZFS: Better Living Through Filesystems
Kafka on ZFS: Better Living Through Filesystems
 
Introduction to Memoria
Introduction to MemoriaIntroduction to Memoria
Introduction to Memoria
 
Concept of thread
Concept of threadConcept of thread
Concept of thread
 
Caching in (DevoxxUK 2013)
Caching in (DevoxxUK 2013)Caching in (DevoxxUK 2013)
Caching in (DevoxxUK 2013)
 
Coherence and consistency models in multiprocessor architecture
Coherence and consistency models in multiprocessor architectureCoherence and consistency models in multiprocessor architecture
Coherence and consistency models in multiprocessor architecture
 
Cassandra On EC2
Cassandra On EC2Cassandra On EC2
Cassandra On EC2
 
Kernel Recipes 2014 - Performance Does Matter
Kernel Recipes 2014 - Performance Does MatterKernel Recipes 2014 - Performance Does Matter
Kernel Recipes 2014 - Performance Does Matter
 
Introduction to multi core
Introduction to multi coreIntroduction to multi core
Introduction to multi core
 
Multicore
MulticoreMulticore
Multicore
 
Caching in
Caching inCaching in
Caching in
 
Mongo nyc nyt + mongodb
Mongo nyc nyt + mongodbMongo nyc nyt + mongodb
Mongo nyc nyt + mongodb
 
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
 
Recent advancements in cache technology
Recent advancements in cache technologyRecent advancements in cache technology
Recent advancements in cache technology
 

Plus de Robert Burrell Donkin

If the Data Cannot Come To The Algorithm...
If the Data Cannot Come To The Algorithm...If the Data Cannot Come To The Algorithm...
If the Data Cannot Come To The Algorithm...
Robert Burrell Donkin
 

Plus de Robert Burrell Donkin (9)

Threads and Threads
Threads and ThreadsThreads and Threads
Threads and Threads
 
If the Data Cannot Come To The Algorithm...
If the Data Cannot Come To The Algorithm...If the Data Cannot Come To The Algorithm...
If the Data Cannot Come To The Algorithm...
 
Many Cores Java - Session One: Threads and Threads
Many Cores Java - Session One: Threads and ThreadsMany Cores Java - Session One: Threads and Threads
Many Cores Java - Session One: Threads and Threads
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
XP In 10 slides
XP In 10 slidesXP In 10 slides
XP In 10 slides
 
Public Sector: Agile and Open Source
Public Sector: Agile and Open SourcePublic Sector: Agile and Open Source
Public Sector: Agile and Open Source
 
An Agile Pick-N-Mix
An Agile Pick-N-MixAn Agile Pick-N-Mix
An Agile Pick-N-Mix
 
The Pomodoro Technique: Introduced Unofficially In 10 Slides
The Pomodoro Technique: Introduced Unofficially In 10 SlidesThe Pomodoro Technique: Introduced Unofficially In 10 Slides
The Pomodoro Technique: Introduced Unofficially In 10 Slides
 
Retrospectives In 10 Slides (With Notes)
Retrospectives In 10 Slides  (With Notes)Retrospectives In 10 Slides  (With Notes)
Retrospectives In 10 Slides (With Notes)
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Threads - Why Can't You Just Play Nicely With Your Memory?

  • 1. Threads - Why Can't You Just Play Nicely With Your Memory? many cores with java session three two cores copyright 2013 Robert Burrell Donkin robertburrelldonkin.name this work is licensed under a Creative Commons Attribution 3.0 Unported License
  • 2. Pre-emptive multi-tasking operating systems use involuntary context switching to provide the illusion of parallel processes even when the hardware supports only a single thread of execution. Take Away from Session One
  • 3. Even on a single core, there's no escaping parallelism. Take Away from Session Two
  • 4. Two Cores on One Chip ● Share caches ○ not L1 ○ perhaps L2 ○ probably L3 ● Communicate fast and fat ○ in comparison to IO: very fast ○ in comparison to memory: fast ○ in comparison to intra-core: slow ● Cache consistency is cheap(er)
  • 5. Two Cores on Two Chip ● No share caches ○ not L1 ○ not L2 ○ not L3 ○ share only main memory ● Communicate maybe...? ○ in comparison to IO: fast ○ in comparison to memory: so-so ○ in comparison to intra-core: very slow ● Consistency is expensive
  • 6. When Memory is Shared ● Until memory is shared ○ compiler, ○ hardware and ○ operating system ○ sweep the messy details under the rug ● When memory is shared ○ the software platform ○ guarantees reasonable behaviour ○ when code plays by the rules
  • 7. Some Software Strategies ● Applicable to any shared resource ○ but memory as an example is ■ convenient and ■ common ● Mutual exclusion ○ no concurrent access to critical sections ● Non-blocking algorithms ○ CAS - compare and swap
  • 8. Locks ● Block threads ○ which do not hold the lock ○ from a critical section ● When thread holding the lock ○ exits the critical section ○ other threads may no longer be blocked
  • 9. Reading Stale Data ● Recall ○ that caches are not always coherent ○ two cores and main memory may not agree about a value for a memory location ● Mutual exclusion is often not enough ○ memory barrier needed ○ hardware ensures data is coherent ○ expensive ● In Java, synchronized ○ locks and ○ issues memory barrier
  • 10. ● Several ways to implement in hardware ● When writing a value: ○ send expected existing value ○ return actual existing value on failure ● Step along the road to transactional memory ○ Similar to optimistic locking in an RDBMS CAS - Compare and Swap
  • 11. Take Away Code executing on different cores uses copies held in registers and caches, so memory shared is likely to be incoherent unless the program plays by the rules of the software platform.