ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Threads and Threads
session one
starting with a single core
copyright 2013 Robert Burrell Donkin robertburrelldonkin.name
this work is licensed under a Creative Commons Attribution 3.0 Unported License
Threads, Threads and Processes
from the
¡ñ hardware perspective
¡ð a thread is a serial code sequence
¡ñ software perspective
¡ð a thread abstracts a serial code sequence
¡ñ operating system perspective
¡ð a process abstracts an application instance
Multi-tasking a Single Core
¡ñ on a single core
¡ð a multitasking operating system
¡ö uses scheduling
¡ö to create the illusion of parallelism
¡ñ a software platform may also
¡ð use scheduling to create the illusion of parallelism
¡ð but then this is more often called multi-threading
Approaches to Multi-Tasking
¡ñ cooperative (or voluntary) multi-tasking
¡ð time-sharing
¡ð background processing
¡ð early Apple PCs
¡ð now rarely used
¡ñ pre-emptive multi-tasking
¡ð time-slicing
¡ð Windows 95 PCs
¡ð now almost universal
Why Multi-Task...?
¡ñ liveliness
¡ñ responsiveness
¡ð (to people)
¡ñ performance
¡ð (sometimes)
Context Switch
¡ñ a context switch
¡ð stores the current execute state, and
¡ð restores an execution state from storage
¡ñ from a CPU perspective
¡ð this is an expensive operation
¡ñ but is often cheap in comparison
Caches, Caches, Caches
¡ñ Moore's Law
¡ð the number of transistors doubles every 2 years
¡ñ but
¡ð diminishing returns from longer pipelines
¡ð popularity of multi-tasking
¡ñ so more and bigger caches
¡ñ so context switching cost now usually low
¡ñ but scales in a non-linear fashion
¡ñ excessive context switching expensive
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
Break Out
¡ñ Exercises
¡ð https://github.com/RobertBurrellDonkin/kata-manycore-
threadsandthreads
¡ñ Try
¡ð On Windows
¡ö perfmon
¡ö typeperf
¡ð On Linux
¡ö vmstat
¡ö iostat
¡ö mpstat

More Related Content

What's hot (19)

Linux NUMA & Databases: Perils and Opportunities
Linux NUMA & Databases: Perils and OpportunitiesLinux NUMA & Databases: Perils and Opportunities
Linux NUMA & Databases: Perils and Opportunities
Raghavendra Prabhu
?
Threads - Why Can't You Just Play Nicely With Your Memory_
Threads - Why Can't You Just Play Nicely With Your Memory_Threads - Why Can't You Just Play Nicely With Your Memory_
Threads - Why Can't You Just Play Nicely With Your Memory_
Robert Burrell Donkin
?
Mosix Cluster
Mosix ClusterMosix Cluster
Mosix Cluster
Abhay Pai
?
Presentation on flynn¡¯s classification
Presentation on flynn¡¯s classificationPresentation on flynn¡¯s classification
Presentation on flynn¡¯s classification
vani gupta
?
Zk meetup talk
Zk meetup talkZk meetup talk
Zk meetup talk
Yisheng Liao
?
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQ
Luke Luo
?
Coal 16 mapping in Assembly Programming
Coal 16 mapping in Assembly ProgrammingCoal 16 mapping in Assembly Programming
Coal 16 mapping in Assembly Programming
Muhammad Taqi Hassan Bukhari
?
L03
L03L03
L03
International advisers
?
Flynn taxonomies
Flynn taxonomiesFlynn taxonomies
Flynn taxonomies
Srujan Damera
?
Flynn's classification
Flynn's classificationFlynn's classification
Flynn's classification
Hamidul Islam
?
L04
L04L04
L04
International advisers
?
Aca2 07 new
Aca2 07 newAca2 07 new
Aca2 07 new
Sumit Mittu
?
Modeling & design multi-core NUMA simulator
Modeling & design multi-core NUMA simulatorModeling & design multi-core NUMA simulator
Modeling & design multi-core NUMA simulator
Abed Maatalla
?
Lecture4
Lecture4Lecture4
Lecture4
tt_aljobory
?
SUZETTE TEGA(CHS-EDP)
SUZETTE TEGA(CHS-EDP)SUZETTE TEGA(CHS-EDP)
SUZETTE TEGA(CHS-EDP)
guest66310a
?
Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...
Alexey Ivanov
?
Resource Management with Systemd and cgroups
Resource Management with Systemd and cgroupsResource Management with Systemd and cgroups
Resource Management with Systemd and cgroups
Tsung-en Hsiao
?
Transaction Process System and Recovery
Transaction Process System and RecoveryTransaction Process System and Recovery
Transaction Process System and Recovery
Jitendra Thakur
?
Aca2 01 new
Aca2 01 newAca2 01 new
Aca2 01 new
Sumit Mittu
?
Linux NUMA & Databases: Perils and Opportunities
Linux NUMA & Databases: Perils and OpportunitiesLinux NUMA & Databases: Perils and Opportunities
Linux NUMA & Databases: Perils and Opportunities
Raghavendra Prabhu
?
Threads - Why Can't You Just Play Nicely With Your Memory_
Threads - Why Can't You Just Play Nicely With Your Memory_Threads - Why Can't You Just Play Nicely With Your Memory_
Threads - Why Can't You Just Play Nicely With Your Memory_
Robert Burrell Donkin
?
Presentation on flynn¡¯s classification
Presentation on flynn¡¯s classificationPresentation on flynn¡¯s classification
Presentation on flynn¡¯s classification
vani gupta
?
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQ
Luke Luo
?
Modeling & design multi-core NUMA simulator
Modeling & design multi-core NUMA simulatorModeling & design multi-core NUMA simulator
Modeling & design multi-core NUMA simulator
Abed Maatalla
?
SUZETTE TEGA(CHS-EDP)
SUZETTE TEGA(CHS-EDP)SUZETTE TEGA(CHS-EDP)
SUZETTE TEGA(CHS-EDP)
guest66310a
?
Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...
Alexey Ivanov
?
Resource Management with Systemd and cgroups
Resource Management with Systemd and cgroupsResource Management with Systemd and cgroups
Resource Management with Systemd and cgroups
Tsung-en Hsiao
?
Transaction Process System and Recovery
Transaction Process System and RecoveryTransaction Process System and Recovery
Transaction Process System and Recovery
Jitendra Thakur
?

Viewers also liked (17)

Apache Maven In 10 ºÝºÝߣs
Apache Maven In 10 ºÝºÝߣsApache Maven In 10 ºÝºÝߣs
Apache Maven In 10 ºÝºÝߣs
Robert Burrell Donkin
?
An Agile Pick-N-Mix
An Agile Pick-N-MixAn Agile Pick-N-Mix
An Agile Pick-N-Mix
Robert Burrell Donkin
?
Public Sector: Agile and Open Source
Public Sector: Agile and Open SourcePublic Sector: Agile and Open Source
Public Sector: Agile and Open Source
Robert Burrell Donkin
?
Retrospectives In 10 ºÝºÝߣs (With Notes)
Retrospectives In 10 ºÝºÝߣs  (With Notes)Retrospectives In 10 ºÝºÝߣs  (With Notes)
Retrospectives In 10 ºÝºÝߣs (With Notes)
Robert Burrell Donkin
?
Why finding a balance between inspiration and perspiration is key to success ...
Why finding a balance between inspiration and perspiration is key to success ...Why finding a balance between inspiration and perspiration is key to success ...
Why finding a balance between inspiration and perspiration is key to success ...
Alchemy Worx
?
Creating Loyalty Programs
Creating Loyalty ProgramsCreating Loyalty Programs
Creating Loyalty Programs
Alchemy Worx
?
Beyond the Open Rate: It's Time to Think Reach Frequency and Impact
Beyond the Open Rate: It's Time to Think Reach Frequency and ImpactBeyond the Open Rate: It's Time to Think Reach Frequency and Impact
Beyond the Open Rate: It's Time to Think Reach Frequency and Impact
Alchemy Worx
?
Alchemy Worx design portfolio May 2013
Alchemy Worx design portfolio May 2013Alchemy Worx design portfolio May 2013
Alchemy Worx design portfolio May 2013
Alchemy Worx
?
7 Myths of Email Marketing - Alchemy Worx
7 Myths of Email Marketing - Alchemy Worx7 Myths of Email Marketing - Alchemy Worx
7 Myths of Email Marketing - Alchemy Worx
Alchemy Worx
?
An End to Order
An End to OrderAn End to Order
An End to Order
Robert Burrell Donkin
?
Defining Engagement - the Problem with Opens and Clicks
Defining Engagement - the Problem with Opens and ClicksDefining Engagement - the Problem with Opens and Clicks
Defining Engagement - the Problem with Opens and Clicks
Alchemy Worx
?
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
?
WhichTestWon The Live Event: Subject Line Optimization Masterclass
WhichTestWon The Live Event: Subject Line Optimization MasterclassWhichTestWon The Live Event: Subject Line Optimization Masterclass
WhichTestWon The Live Event: Subject Line Optimization Masterclass
Alchemy Worx
?
XP In 10 slides
XP In 10 slidesXP In 10 slides
XP In 10 slides
Robert Burrell Donkin
?
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)
Robert Burrell Donkin
?
Email as a Mass Media Channel
Email as a Mass Media ChannelEmail as a Mass Media Channel
Email as a Mass Media Channel
Alchemy Worx
?
E-mail Marketing 3.0 is coming: Are you ready?
E-mail Marketing 3.0 is coming: Are you ready?E-mail Marketing 3.0 is coming: Are you ready?
E-mail Marketing 3.0 is coming: Are you ready?
Alchemy Worx
?
Retrospectives In 10 ºÝºÝߣs (With Notes)
Retrospectives In 10 ºÝºÝߣs  (With Notes)Retrospectives In 10 ºÝºÝߣs  (With Notes)
Retrospectives In 10 ºÝºÝߣs (With Notes)
Robert Burrell Donkin
?
Why finding a balance between inspiration and perspiration is key to success ...
Why finding a balance between inspiration and perspiration is key to success ...Why finding a balance between inspiration and perspiration is key to success ...
Why finding a balance between inspiration and perspiration is key to success ...
Alchemy Worx
?
Creating Loyalty Programs
Creating Loyalty ProgramsCreating Loyalty Programs
Creating Loyalty Programs
Alchemy Worx
?
Beyond the Open Rate: It's Time to Think Reach Frequency and Impact
Beyond the Open Rate: It's Time to Think Reach Frequency and ImpactBeyond the Open Rate: It's Time to Think Reach Frequency and Impact
Beyond the Open Rate: It's Time to Think Reach Frequency and Impact
Alchemy Worx
?
Alchemy Worx design portfolio May 2013
Alchemy Worx design portfolio May 2013Alchemy Worx design portfolio May 2013
Alchemy Worx design portfolio May 2013
Alchemy Worx
?
7 Myths of Email Marketing - Alchemy Worx
7 Myths of Email Marketing - Alchemy Worx7 Myths of Email Marketing - Alchemy Worx
7 Myths of Email Marketing - Alchemy Worx
Alchemy Worx
?
Defining Engagement - the Problem with Opens and Clicks
Defining Engagement - the Problem with Opens and ClicksDefining Engagement - the Problem with Opens and Clicks
Defining Engagement - the Problem with Opens and Clicks
Alchemy Worx
?
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
?
WhichTestWon The Live Event: Subject Line Optimization Masterclass
WhichTestWon The Live Event: Subject Line Optimization MasterclassWhichTestWon The Live Event: Subject Line Optimization Masterclass
WhichTestWon The Live Event: Subject Line Optimization Masterclass
Alchemy Worx
?
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)
Robert Burrell Donkin
?
Email as a Mass Media Channel
Email as a Mass Media ChannelEmail as a Mass Media Channel
Email as a Mass Media Channel
Alchemy Worx
?
E-mail Marketing 3.0 is coming: Are you ready?
E-mail Marketing 3.0 is coming: Are you ready?E-mail Marketing 3.0 is coming: Are you ready?
E-mail Marketing 3.0 is coming: Are you ready?
Alchemy Worx
?

Similar to Threads and Threads (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
Syed Zaid Irshad
?
Threads and processes
Threads and processesThreads and processes
Threads and processes
Fungirayiini Chiweshe Mushaninga
?
Class 1
Class   1Class   1
Class 1
dduncan3
?
Linux Locking Mechanisms
Linux Locking MechanismsLinux Locking Mechanisms
Linux Locking Mechanisms
Kernel TLV
?
PyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingPyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous Programming
Juti Noppornpitak
?
Lec 9-os-review
Lec 9-os-reviewLec 9-os-review
Lec 9-os-review
Mothi R
?
Efficient Buffer Management
Efficient Buffer ManagementEfficient Buffer Management
Efficient Buffer Management
basisspace
?
Functional? Reactive? Why?
Functional? Reactive? Why?Functional? Reactive? Why?
Functional? Reactive? Why?
Aleksandr Tavgen
?
Realtime
RealtimeRealtime
Realtime
Mark Veltzer
?
Threads - Why Can't You Just Play Nicely With Your Memory?
Threads - Why Can't You Just Play Nicely With Your Memory?Threads - Why Can't You Just Play Nicely With Your Memory?
Threads - Why Can't You Just Play Nicely With Your Memory?
Robert Burrell Donkin
?
Multithreaded Programming in oprating system
Multithreaded Programming in oprating  systemMultithreaded Programming in oprating  system
Multithreaded Programming in oprating system
YOGENDRAMS
?
linux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
linux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaalinux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
linux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
YasaswiniChintamalla1
?
General Purpose GPU Computing
General Purpose GPU ComputingGeneral Purpose GPU Computing
General Purpose GPU Computing
GlobalLogic Ukraine
?
Concurrency, Parallelism And IO
Concurrency,  Parallelism And IOConcurrency,  Parallelism And IO
Concurrency, Parallelism And IO
Piyush Katariya
?
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
Emertxe Information Technologies Pvt Ltd
?
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
Emertxe Information Technologies Pvt Ltd
?
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
ScyllaDB
?
Optimizing Linux Servers
Optimizing Linux ServersOptimizing Linux Servers
Optimizing Linux Servers
Davor Guttierrez
?
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...
ScyllaDB
?
Operating System concepts
Operating System conceptsOperating System concepts
Operating System concepts
E.M.G.yadava womens college
?
Linux Locking Mechanisms
Linux Locking MechanismsLinux Locking Mechanisms
Linux Locking Mechanisms
Kernel TLV
?
PyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingPyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous Programming
Juti Noppornpitak
?
Lec 9-os-review
Lec 9-os-reviewLec 9-os-review
Lec 9-os-review
Mothi R
?
Efficient Buffer Management
Efficient Buffer ManagementEfficient Buffer Management
Efficient Buffer Management
basisspace
?
Threads - Why Can't You Just Play Nicely With Your Memory?
Threads - Why Can't You Just Play Nicely With Your Memory?Threads - Why Can't You Just Play Nicely With Your Memory?
Threads - Why Can't You Just Play Nicely With Your Memory?
Robert Burrell Donkin
?
Multithreaded Programming in oprating system
Multithreaded Programming in oprating  systemMultithreaded Programming in oprating  system
Multithreaded Programming in oprating system
YOGENDRAMS
?
linux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
linux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaalinux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
linux_internals_2.3 (1).pdf ¨¤aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
YasaswiniChintamalla1
?
Concurrency, Parallelism And IO
Concurrency,  Parallelism And IOConcurrency,  Parallelism And IO
Concurrency, Parallelism And IO
Piyush Katariya
?
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
ScyllaDB
?
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...
ScyllaDB
?

Threads and Threads

  • 1. Threads and Threads session one starting with a single core copyright 2013 Robert Burrell Donkin robertburrelldonkin.name this work is licensed under a Creative Commons Attribution 3.0 Unported License
  • 2. Threads, Threads and Processes from the ¡ñ hardware perspective ¡ð a thread is a serial code sequence ¡ñ software perspective ¡ð a thread abstracts a serial code sequence ¡ñ operating system perspective ¡ð a process abstracts an application instance
  • 3. Multi-tasking a Single Core ¡ñ on a single core ¡ð a multitasking operating system ¡ö uses scheduling ¡ö to create the illusion of parallelism ¡ñ a software platform may also ¡ð use scheduling to create the illusion of parallelism ¡ð but then this is more often called multi-threading
  • 4. Approaches to Multi-Tasking ¡ñ cooperative (or voluntary) multi-tasking ¡ð time-sharing ¡ð background processing ¡ð early Apple PCs ¡ð now rarely used ¡ñ pre-emptive multi-tasking ¡ð time-slicing ¡ð Windows 95 PCs ¡ð now almost universal
  • 5. Why Multi-Task...? ¡ñ liveliness ¡ñ responsiveness ¡ð (to people) ¡ñ performance ¡ð (sometimes)
  • 6. Context Switch ¡ñ a context switch ¡ð stores the current execute state, and ¡ð restores an execution state from storage ¡ñ from a CPU perspective ¡ð this is an expensive operation ¡ñ but is often cheap in comparison
  • 7. Caches, Caches, Caches ¡ñ Moore's Law ¡ð the number of transistors doubles every 2 years ¡ñ but ¡ð diminishing returns from longer pipelines ¡ð popularity of multi-tasking ¡ñ so more and bigger caches ¡ñ so context switching cost now usually low ¡ñ but scales in a non-linear fashion ¡ñ excessive context switching expensive
  • 8. 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
  • 9. Break Out ¡ñ Exercises ¡ð https://github.com/RobertBurrellDonkin/kata-manycore- threadsandthreads ¡ñ Try ¡ð On Windows ¡ö perfmon ¡ö typeperf ¡ð On Linux ¡ö vmstat ¡ö iostat ¡ö mpstat