SlideShare a Scribd company logo
Concurrency in C++

                Peter A. Buhr


http: //plg.uwaterloo.ca / ˜ usystem /uC++.html
1 Introduction
1.1 Why Concurrency
 • Processor speed has slowed (stopped).
 • Use transistors from Moore’s law for parallelism to increase speed.
 • But concurrent programming is necessary to utilize parallel hardware.
 • Some success in implicitly discovering concurrency in sequential
   programs.
 • Fundamental limits to finding parallelism and only for certain kinds of
   problems.
 • Alternatively, programmer explicitly thinks about and specifies the
   concurrency.
 • Implicit and explicit approaches are complementary, i.e., can appear
   together.
 • However, the limitations of the implicit approach mandate an explicit
   approach.
   Except as otherwise noted, the content of this presentation is licensed under the Creative Com-
mons Attribution 2.5 License.

                                                2
3
1.2 Why C++
• C+ is one of the dominant programming languages.
    +
• Why?
  – based on C, which has a large programmer and code base,
  – as efficient as C in most situations,
  – low-level features, e.g., direct memory access, needed for:
    ∗ systems programming
    ∗ memory management
    ∗ embedded / real-time
  – high-level features, e.g., objects, polymorphism, exception handling,
    STL, etc., which programmers now demand,
  – allows direct interaction with UNIX/Windows.

1.3 Concurrency in C++
• C+ has no concurrency!
    +
• Many different concurrency approaches for C+ have been implemented
                                              +
  with only varying degrees of adoption.
4
• No de facto approach dominating concurrent programming in C+   +.
   – C has two dominant but incompatible concurrency libraries: pthreads
     and Win32.
• C+ lack of concurrency limits its future in the parallel domain.
     +’s
• Therefore, it is imperative C+ be augmented with concurrency facilities
                                +
  to extend its programming base.
• Interestingly, concurrency CANNOT be safely added to ANY language
  via library code.

1.4 High-Level Concurrency
• Want a single consistent high-level powerful concurrency mechanism,
  but what should it look like?
• In theory, any high-level concurrency paradigm/model can be adapted
  into C+ +.
• However, C+ does not support all concurrency approaches equally well,
                +
  e.g., tuple space, message passing, channels.
• C+ is fundamentally based on a class model using routine call, and its
    +
  other features leverage this model.
5
• Any concurrency approach matching the C+ model is better served
                                              +
  because its concepts interact consistently with the language.
• Apply “Principle of Least Astonishment” whenever possible.
• Let C+ dictate which concurrency approaches fits best via its design
        +
  principles.
• For OO language, thread/stack is best associated with class, and
  mutual-exclusion/synchronization with member routines.

1.5 µC+ : Advanced Control Flow for C+
       +                              +
• integrate advanced control flow tightly into C++
   – leverage all class features
   – threads are light-weight: M:N thread model versus 1:1
• use mutex objects to contain mutual exclusion and synchronization
   – communication using routine call (versus messages/channels)
   – statically typed
• handle multi-processor environment
6
1.6 Outline
• coroutines : suspending and resuming (concurrency precursor)
• concurrency : introduce multiple threads
• locking : thread control through synchronization and mutual exclusion
• errors : new concurrency issues
• monitors : high-level thread control
• tasks : active objects
• other concurrent approaches : different concurrency paradigms

More Related Content

ODP
Cp3-- A module support tool for C++
PDF
Model-Driven Analysis&Design of Distributed, Heterogeneous Systems
PPT
Authentication (Distributed computing)
PPT
Network and distributed systems
PPT
Distributed file systems
PPTX
Introduction to Distributed Architecture
PDF
C Concurrency In Action 1st Edition Anthony Williams
PDF
C Concurrency In Action Practical Multithreading 1st Edition Anthony Williams
Cp3-- A module support tool for C++
Model-Driven Analysis&Design of Distributed, Heterogeneous Systems
Authentication (Distributed computing)
Network and distributed systems
Distributed file systems
Introduction to Distributed Architecture
C Concurrency In Action 1st Edition Anthony Williams
C Concurrency In Action Practical Multithreading 1st Edition Anthony Williams

Similar to Introduction to Concurrency (20)

PDF
PDF
Other Approaches (Concurrency)
PDF
Concurrency
PDF
Threads lecture slides for operating systems
PDF
ThreadModel rev 1.4
PDF
Concurrency in Smalltalk -- Beyond Threads
PDF
Concurrency Issues in Object-Oriented Modeling
PDF
Object Oriented Programming using C++ - Part 1
PPTX
Programming using C++ - slides.pptx
PPTX
Async await in C++
PDF
Highly concurrent yet natural programming
PDF
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
PPTX
Seminar on Parallel and Concurrent Programming
PDF
Topic 4: Concurrency
PDF
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
PDF
Our Concurrent Past; Our Distributed Future
PPTX
C+Comprehensive overview of the IoT system aims, architecture, challenges, ap...
PPTX
Interactions complicate debugging
PDF
Ruby's Concurrency Management: Now and Future
PPTX
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Other Approaches (Concurrency)
Concurrency
Threads lecture slides for operating systems
ThreadModel rev 1.4
Concurrency in Smalltalk -- Beyond Threads
Concurrency Issues in Object-Oriented Modeling
Object Oriented Programming using C++ - Part 1
Programming using C++ - slides.pptx
Async await in C++
Highly concurrent yet natural programming
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
Seminar on Parallel and Concurrent Programming
Topic 4: Concurrency
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
Our Concurrent Past; Our Distributed Future
C+Comprehensive overview of the IoT system aims, architecture, challenges, ap...
Interactions complicate debugging
Ruby's Concurrency Management: Now and Future
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Ad

More from Sri Prasanna (20)

PDF
Qr codes para tech radar
PDF
Qr codes para tech radar 2
DOC
DOC
PDF
PDF
PDF
PDF
PDF
About stacks
PDF
About Stacks
PDF
About Stacks
PDF
About Stacks
PDF
About Stacks
PDF
About Stacks
PDF
About Stacks
PDF
About Stacks
PPT
Introduction & Parellelization on large scale clusters
PPT
Mapreduce: Theory and implementation
PPT
Other distributed systems
PPT
Introduction to Cluster Computing and Map Reduce (from Google)
Qr codes para tech radar
Qr codes para tech radar 2
About stacks
About Stacks
About Stacks
About Stacks
About Stacks
About Stacks
About Stacks
About Stacks
Introduction & Parellelization on large scale clusters
Mapreduce: Theory and implementation
Other distributed systems
Introduction to Cluster Computing and Map Reduce (from Google)
Ad

Recently uploaded (20)

PDF
IGGE1 Understanding the Self1234567891011
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
Empowerment Technology for Senior High School Guide
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Types and Its function , kingdom of life
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Indian roads congress 037 - 2012 Flexible pavement
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
advance database management system book.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Lesson notes of climatology university.
PDF
RMMM.pdf make it easy to upload and study
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
IGGE1 Understanding the Self1234567891011
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Unit 4 Skeletal System.ppt.pptxopresentatiom
Empowerment Technology for Senior High School Guide
Computing-Curriculum for Schools in Ghana
Cell Types and Its function , kingdom of life
History, Philosophy and sociology of education (1).pptx
Final Presentation General Medicine 03-08-2024.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Indian roads congress 037 - 2012 Flexible pavement
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Paper A Mock Exam 9_ Attempt review.pdf.
advance database management system book.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
A systematic review of self-coping strategies used by university students to ...
Lesson notes of climatology university.
RMMM.pdf make it easy to upload and study
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين

Introduction to Concurrency

  • 1. Concurrency in C++ Peter A. Buhr http: //plg.uwaterloo.ca / ˜ usystem /uC++.html
  • 2. 1 Introduction 1.1 Why Concurrency • Processor speed has slowed (stopped). • Use transistors from Moore’s law for parallelism to increase speed. • But concurrent programming is necessary to utilize parallel hardware. • Some success in implicitly discovering concurrency in sequential programs. • Fundamental limits to finding parallelism and only for certain kinds of problems. • Alternatively, programmer explicitly thinks about and specifies the concurrency. • Implicit and explicit approaches are complementary, i.e., can appear together. • However, the limitations of the implicit approach mandate an explicit approach. Except as otherwise noted, the content of this presentation is licensed under the Creative Com- mons Attribution 2.5 License. 2
  • 3. 3 1.2 Why C++ • C+ is one of the dominant programming languages. + • Why? – based on C, which has a large programmer and code base, – as efficient as C in most situations, – low-level features, e.g., direct memory access, needed for: ∗ systems programming ∗ memory management ∗ embedded / real-time – high-level features, e.g., objects, polymorphism, exception handling, STL, etc., which programmers now demand, – allows direct interaction with UNIX/Windows. 1.3 Concurrency in C++ • C+ has no concurrency! + • Many different concurrency approaches for C+ have been implemented + with only varying degrees of adoption.
  • 4. 4 • No de facto approach dominating concurrent programming in C+ +. – C has two dominant but incompatible concurrency libraries: pthreads and Win32. • C+ lack of concurrency limits its future in the parallel domain. +’s • Therefore, it is imperative C+ be augmented with concurrency facilities + to extend its programming base. • Interestingly, concurrency CANNOT be safely added to ANY language via library code. 1.4 High-Level Concurrency • Want a single consistent high-level powerful concurrency mechanism, but what should it look like? • In theory, any high-level concurrency paradigm/model can be adapted into C+ +. • However, C+ does not support all concurrency approaches equally well, + e.g., tuple space, message passing, channels. • C+ is fundamentally based on a class model using routine call, and its + other features leverage this model.
  • 5. 5 • Any concurrency approach matching the C+ model is better served + because its concepts interact consistently with the language. • Apply “Principle of Least Astonishment” whenever possible. • Let C+ dictate which concurrency approaches fits best via its design + principles. • For OO language, thread/stack is best associated with class, and mutual-exclusion/synchronization with member routines. 1.5 µC+ : Advanced Control Flow for C+ + + • integrate advanced control flow tightly into C++ – leverage all class features – threads are light-weight: M:N thread model versus 1:1 • use mutex objects to contain mutual exclusion and synchronization – communication using routine call (versus messages/channels) – statically typed • handle multi-processor environment
  • 6. 6 1.6 Outline • coroutines : suspending and resuming (concurrency precursor) • concurrency : introduce multiple threads • locking : thread control through synchronization and mutual exclusion • errors : new concurrency issues • monitors : high-level thread control • tasks : active objects • other concurrent approaches : different concurrency paradigms