std::async() in C++11 Basic Multithreading

Size: px
Start display at page:

Download "std::async() in C++11 Basic Multithreading"

Transcription

1 MÜNSTER std::async() in C++11 Basic Multithreading 2. December 2015

2 std::thread MÜNSTER std::async() in C /14 #include <thread> void hello(){ std::cout << "Hello from thread" << std::endl; std::thread t1(hello); t1.join(); Compile: g++ -std=c++11 -pthread foo.cpp

3 std::async() MÜNSTER std::async() in C /14 #include <future> void hello(){ std::cout << "Hello from thread" << std::endl; std::future<void> f1 = std::async(hello); f1.wait(); Compile: g++ -std=c++11 -pthread foo.cpp

4 MÜNSTER std::async() in C /14 std::thread with Arguments #include <thread> void hello(std::string message){ std::cout << message << " from thread" << std::endl; std::thread t1(hello "Guten Tag"); t1.join(); Compile: g++ -std=c++11 -pthread foo.cpp

5 MÜNSTER std::async() in C /14 std::async() with Arguments #include <future> void hello(std::string message){ std::cout << message << " from thread" << std::endl; std::future<void> f1 = std::async(hello "Guten Tag"); f1.wait(); Compile: g++ -std=c++11 -pthread foo.cpp

6 std::future<t> MÜNSTER std::async() in C /14

7 std::future<t> MÜNSTER std::async() in C /14 Interface: void wait(); T get();

8 MÜNSTER std::async() in C /14 std::async() with Result #include <future> double calculate(){ double result = 42.; // very expensive calculation return result; std::future<double> f1 = std::async(calculate); // do something else in the meantime std::cout << "The result is " << f1.get() << std::endl;

9 MÜNSTER std::async() in C /14 std::async() with Exception #include <future> double calculate(){ throw std::runtime_error("end of the world"); std::future<double> f1 = std::async(calculate); try{ std::cout << "Result: " << f1.get() << std::endl; catch (std::exception& e){ std::cout << "Error: " << e.what() << std::endl;

10 Launch Policies MÜNSTER std::async() in C /14 #include <future> void hello(){ std::cout << "Hello from thread" << std::endl; std::future<void> f1 = std::async(std::launch::deferred hello); f1.wait();

11 Policies MÜNSTER std::async() in C /14 std::launch::async New thread launched std::launch::deferred No thread execution in wait() or get() Default: let implementation decide.

12 Pitfalls MÜNSTER std::async() in C /14 g++ default policy is deferred so no parallel execution by default. Implicit wait() in destructor of future with async policy. std::async(std::launch::asyncmyfunction); This is a synchronous call.

13 Not parallel MÜNSTER std::async() in C /14 #include <future> #include <thread> void wait(){ std::cout << "start waiting" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "stop waiting" << std::endl; std::async(std::launch::asyncwait); std::async(std::launch::asyncwait);

14 Parallel MÜNSTER std::async() in C /14 #include <future> #include <thread> void wait(){ std::cout << "start waiting" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "stop waiting" << std::endl; auto f1 = std::async(std::launch::asyncwait); auto f2 = std::async(std::launch::asyncwait);

15 Summary MÜNSTER std::async() in C /14 std::async interface similar to std::thread. Result and/or exceptions are propagated back through std::future. Two start policies async and deferred. Only async starts a thread. Make sure to save the future ;-).

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1. COMP6771 Advanced C++ Programming Week 10 Multithreading - Producer/Consumer Problem 2016 www.cse.unsw.edu.au/ cs6771 2. : C++11 Mutexes C++11 provides Mutex objects in the header file. General

More information

tcsc 2016 Luca Brianza 1 Luca Brianza 19/07/16 INFN & University of Milano-Bicocca

tcsc 2016 Luca Brianza 1 Luca Brianza 19/07/16 INFN & University of Milano-Bicocca tcsc 2016 1 1 INFN & University of Milano-Bicocca Outlook Amdahl s law Different ways of parallelism: - Asynchronous task execution - Threads Resource protection/thread safety - The problem - Low-level

More information

Joe Hummel, PhD. U. of Illinois, Chicago

Joe Hummel, PhD. U. of Illinois, Chicago Joe Hummel, PhD U. of Illinois, Chicago jhummel2@uic.edu http://www.joehummel.net/downloads.html New standard of C++ has been ratified C++0x ==> C++11 Lots of new features We ll focus on concurrency features

More information

Joe Hummel, PhD. UC-Irvine

Joe Hummel, PhD. UC-Irvine Joe Hummel, PhD UC-Irvine hummelj@ics.uci.edu http://www.joehummel.net/downloads.html New standard of C++ has been ratified C++0x ==> C++11 Lots of new features We ll focus on concurrency features 2 Async

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.... COMP6771 Advanced C++ Programming Week 9 Multithreading 2016 www.cse.unsw.edu.au/ cs6771 .... Single Threaded Programs All programs so far this semester have been single threaded They have a single

More information

Parallel Computing. Prof. Marco Bertini

Parallel Computing. Prof. Marco Bertini Parallel Computing Prof. Marco Bertini Shared memory: C++ threads C++ multithreading It is possible to use Pthreads API within C++ programs. The C++11 standard has introduced support for multithreaded

More information

Concurrent programming in C++11

Concurrent programming in C++11 Concurrent programming in C++11 Computer Architecture J. Daniel García Sánchez (coordinator) David Expósito Singh Francisco Javier García Blas ARCOS Group Computer Science and Engineering Department University

More information

C++ Pub Quiz. A 90 minute quiz session ACCU April by Olve Maudal, with Lars Gullik Bjønnes. Sponsored by:

C++ Pub Quiz. A 90 minute quiz session ACCU April by Olve Maudal, with Lars Gullik Bjønnes. Sponsored by: C++ Pub Quiz by Olve Maudal, with Lars Gullik Bjønnes + + Sponsored by: A 90 minute quiz session ACCU April 2013 Here is my development environment: (Mac OS 10.8.2, x86_64) bash-3.2$ myc++ -v Using built-in

More information

async and ~future (Revision 3)

async and ~future (Revision 3) Doc No: WG21 N3637 Date: 2013-04-17 Reply to: Herb Sutter (hsutter@microsoft.com) Subgroup: SG1 Concurrency Previous Version: N3630 async and ~future (Revision 3) Herb Sutter, Chandler Carruth, Niklas

More information

ECE 3574: Applied Software Design. Threads

ECE 3574: Applied Software Design. Threads ECE 3574: Applied Software Design Threads Today we are going to start looking at threads, multiple executing programs within the same process that share the code segment and heap, but have separate stacks.

More information

C++11 threads -- a simpler interface than pthreads Examples largely taken from https://latedev.wordpress.com/ 013/02/24/investigating-c11-threads/

C++11 threads -- a simpler interface than pthreads Examples largely taken from https://latedev.wordpress.com/ 013/02/24/investigating-c11-threads/ C++11 threads -- a simpler interface than pthreads Examples largely taken from https://latedev.wordpress.com/ 013/02/24/investigating-c11-threads/ #include #include using namespace

More information

PROGRAMOVÁNÍ V C++ CVIČENÍ. Michal Brabec

PROGRAMOVÁNÍ V C++ CVIČENÍ. Michal Brabec PROGRAMOVÁNÍ V C++ CVIČENÍ Michal Brabec PARALLELISM CATEGORIES CPU? SSE Multiprocessor SIMT - GPU 2 / 17 PARALLELISM V C++ Weak support in the language itself, powerful libraries Many different parallelization

More information

9/23/2014. Concurrent Programming. Book. Process. Exchange of data between threads/processes. Between Process. Thread.

9/23/2014. Concurrent Programming. Book. Process. Exchange of data between threads/processes. Between Process. Thread. Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Course Structure & Book Basic of thread and process Coordination and synchronization Example of Parallel Programming Shared memory : C/C++

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1. COMP6771 Advanced C++ Programming Week 9 Multithreading (continued) 2016 www.cse.unsw.edu.au/ cs6771 2. So Far Program Workflows: Sequential, Parallel, Embarrassingly Parallel Memory: Shared Memory,

More information

A <Basic> C++ Course. 12 lambda expressions and concurrency in C++11. Julien Deantoni

A <Basic> C++ Course. 12 lambda expressions and concurrency in C++11. Julien Deantoni A C++ Course 12 lambda expressions and concurrency in C++11 Julien Deantoni Lambda expressions A unnamed function (which is a std::function) Usable in many place like algorithms, thread, [capture](parameters)->return-type

More information

Multithreading in C++0x part 1: Starting Threads

Multithreading in C++0x part 1: Starting Threads https://www.justsoftwaresolutions.co.uk/threading/multithreading in c++0x part 1 starting threads.html 2009/02 ~ 2010/02 Multithreading in C++0x Part 1: Starting Threads Part 2: Starting Threads with Function

More information

Remedial C Now that we can actually use it Pete Williamson

Remedial C Now that we can actually use it Pete Williamson Remedial C++ 11 Now that we can actually use it Pete Williamson (petewil00@hotmail.com) Overview (1) auto lambdas nullptr = default, = delete shared_ptr Range based for loops Overview (2) Uniform initialization

More information

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/35 ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review Professor Jia Wang Department of Electrical

More information

HPX A GENERAL PURPOSE C++ RUNTIME SYSTEM FOR PARALLEL AND DISTRIBUTED APPLICATIONS OF ANY SCALE

HPX A GENERAL PURPOSE C++ RUNTIME SYSTEM FOR PARALLEL AND DISTRIBUTED APPLICATIONS OF ANY SCALE HPX A GENERAL PURPOSE C++ RUNTIME SYSTEM FOR PARALLEL AND DISTRIBUTED APPLICATIONS OF ANY SCALE The Venture Point TECHNOLOGY DEMANDS NEW RESPONSE 2 Technology Demands new Response 3 Technology Demands

More information

Multithreading done right? Rainer Grimm: Multithreading done right?

Multithreading done right? Rainer Grimm: Multithreading done right? Multithreading done right? Overview Threads Shared Variables Thread local data Condition Variables Tasks Memory Model Threads Needs a work package and run immediately The creator has to care of this child

More information

Concurrent Programming in C++ Venkat

Concurrent Programming in C++ Venkat Concurrent Programming in C++ Venkat Subramaniam venkats@agiledeveloper.com @venkat_s Platform Neutral The standard concurrency model makes it possible to write portable concurrent code Level of Concurrency

More information

Concurrent programming in C++11

Concurrent programming in C++11 Concurrent programming in C++11 Multithreading is just one damn thing after, before, or simultaneous with another. --Andrei Alexandrescu Problems with C++98 memory model Double-checked locking pattern

More information

Throwing exceptions 02/12/2018. Throwing objects. Exceptions

Throwing exceptions 02/12/2018. Throwing objects. Exceptions ECE 150 Fundamentals of Programming Outline 2 In this lesson, we will: See that we can throw objects Know that there are classes defined in the standard template library These classes allow more information

More information

Exception Safe Coding

Exception Safe Coding Exception Safe Coding Dirk Hutter hutter@compeng.uni-frankfurt.de Prof. Dr. Volker Lindenstruth FIAS Frankfurt Institute for Advanced Studies Goethe-Universität Frankfurt am Main, Germany http://compeng.uni-frankfurt.de

More information

Assignment #1 Advanced Programming in C /2018. NPRG051 Advanced programming in C++ - Assignment #1

Assignment #1 Advanced Programming in C /2018. NPRG051 Advanced programming in C++ - Assignment #1 Assignment #1 Advanced Programming in C++ 2017/2018 1 Assignment #1 split deadline: Thu 12 Apr 23:59 2 using namespace splitter; std::istringstream iss("alpha:=10/50.1"); std::string x; int y; double z;

More information

Datenstrukturen und Algorithmen

Datenstrukturen und Algorithmen 1 Datenstrukturen und Algorithmen Exercise 12 FS 2018 Program of today 2 1 Feedback of last exercise 2 Repetition theory 3 Programming Tasks 1. Feedback of last exercise 3 Football Championship 4 Club

More information

CS102 C++ Exception Handling & Namespaces

CS102 C++ Exception Handling & Namespaces CS102 C++ Exception Handling & Namespaces Bill Cheng http://merlot.usc.edu/cs102-s12 1 Topics to cover C Structs (Ch 10) C++ Classes (Ch 11) Constructors Destructors Member functions Exception Handling

More information

Database Systems on Modern CPU Architectures

Database Systems on Modern CPU Architectures Database Systems on Modern CPU Architectures Introduction to Modern C++ Moritz Sichert Technische Universität München Department of Informatics Chair of Data Science and Engineering Overview Prerequisites:

More information

Programming in C++: Assignment Week 8

Programming in C++: Assignment Week 8 Programming in C++: Assignment Week 8 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 12,

More information

Exception Handling Alternatives (Part 2)

Exception Handling Alternatives (Part 2) Exception Handling Alternatives (Part 2) First published in Overload 31 Copyright 1999 Detlef Vollmann Resume In part 1, several alternative mechanisms for handling exceptional events were presented. One

More information

Multithreading. A thread is a unit of control (stream of instructions) within a process.

Multithreading. A thread is a unit of control (stream of instructions) within a process. Multithreading A thread is a unit of control (stream of instructions) within a process. When a thread runs, it executes a function in the program. The process associated with a running program starts with

More information

Introduction to Threads

Introduction to Threads Introduction to Threads What is a thread? A thread is an independent stream of instructions scheduled by the operating system to be executed It may be easier to think of this as a procedure that run independently

More information

Using Enum Structs as Bitfields

Using Enum Structs as Bitfields New York C++ Developers Group July 12, 2016 Using Enum Structs as Bitfields Presentation by Jon Kalb Based on an article in Overload magazine by Anthony Williams 1 What do these have in common?! explicit

More information

Improvements to std::future<t> and Related APIs

Improvements to std::future<t> and Related APIs Document number: Supersedes: Date: Reply-to: N3784 N3721 2013-09-27 Niklas Gustafsson < niklas.gustafsson@microsoft.com> Artur Laksberg < arturl@microsoft.com> Herb Sutter < hsutter@microsoft.com> Sana

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.... COMP6771 Advanced C++ Programming Week 5 Part One: Exception Handling 2016 www.cse.unsw.edu.au/ cs6771 2.... Memory Management & Exception Handling.1 Part I: Exception Handling Exception objects

More information

Improvements to std::future<t> and Related APIs

Improvements to std::future<t> and Related APIs Document number: Supersedes: Date: Reply-to: N3634 N3558 2013-05-02 Niklas Gustafsson < niklas.gustafsson@microsoft.com> Artur Laksberg < arturl@microsoft.com> Herb Sutter < hsutter@microsoft.com> Sana

More information

C++ Tutorial AM 225. Dan Fortunato

C++ Tutorial AM 225. Dan Fortunato C++ Tutorial AM 225 Dan Fortunato Anatomy of a C++ program A program begins execution in the main() function, which is called automatically when the program is run. Code from external libraries can be

More information

C++ Exception Handling 1

C++ Exception Handling 1 C++ Exception Handling 1 An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such

More information

ASYNCHRONOUS COMPUTING IN C++

ASYNCHRONOUS COMPUTING IN C++ http://stellar-goup.org ASYNCHRONOUS COMPUTING IN C++ Hartmut Kaiser (Hartmut.Kaiser@gmail.com) CppCon 2014 WHAT IS ASYNCHRONOUS COMPUTING? Spawning off some work without immediately waiting for the work

More information

05-01 Discussion Notes

05-01 Discussion Notes 05-01 Discussion Notes PIC 10B Spring 2018 1 Exceptions 1.1 Introduction Exceptions are used to signify that a function is being used incorrectly. Once an exception is thrown, it is up to the programmer

More information

Polymorphism 02/12/2018. Member functions. Member functions

Polymorphism 02/12/2018. Member functions. Member functions ECE 150 Fundamentals of Programming Outline 2 In this lesson, we will: Introduce the concept of polymorphism Look at its application in: The Shape class to determine whether or not a point is in the image

More information

C++ Namespaces, Exceptions

C++ Namespaces, Exceptions C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design http://www.cplusplus.com/doc/tutorial/namespaces/ http://www.cplusplus.com/doc/tutorial/exceptions/ http://www.cplusplus.com/doc/tutorial/typecasting/

More information

HPX The C++ Standards Library for Concurrency and Parallelism. Hartmut Kaiser

HPX The C++ Standards Library for Concurrency and Parallelism. Hartmut Kaiser HPX The C++ Standards Library for Concurrency and Hartmut Kaiser (hkaiser@cct.lsu.edu) HPX A General Purpose Runtime System The C++ Standards Library for Concurrency and Exposes a coherent and uniform,

More information

The Art, Science, and Engineering of Programming

The Art, Science, and Engineering of Programming Tamino Dauth a and Martin Sulzmann a a Karlsruhe University of Applied Sciences Abstract Futures and promises are a high-level concurrency construct to aid the user in writing scalable and correct asynchronous

More information

C - Grundlagen und Konzepte

C - Grundlagen und Konzepte C - Grundlagen und Konzepte Threads Marcel Hellwig 1hellwig@informatik.uni-hamburg.de Universität Hamburg 5. Juli 2013 SOSE 13 cba This work is licensed under a Creative Commons Attribution-ShareAlike

More information

! Errors can be dealt with at place error occurs

! Errors can be dealt with at place error occurs UCLA Stat 1D Statistical Computing and Visualization in C++ Instructor: Ivo Dinov, Asst. Prof. in Statistics / Neurology University of California, Los Angeles, Winter 200 http://www.stat.ucla.edu/~dinov/courses_students.html

More information

Asynchronous I/O With boost.asio

Asynchronous I/O With boost.asio Asynchronous I/O With boost.asio Avishay Orpaz avishorp@gmail.com @avishorp https://github.com/avishorp SO, You want to make some I/O. SO, You want to make some I/O. That s pretty easy: //Create socket

More information

await/yield: C++ coroutines Zbigniew Skowron 30 November 2016

await/yield: C++ coroutines Zbigniew Skowron 30 November 2016 await/yield: C++ coroutines Zbigniew Skowron 30 November 2016 Agenda Current status Overview and motivation Stackful vs. stackless Coroutines as generators Coroutines instead of callbacks Awaitable types

More information

Consider this example, using the modified version of std::future<t> introduced in N3721:

Consider this example, using the modified version of std::future<t> introduced in N3721: Doc No: N3722 Supersedes: N3650 Date: 2013-08-30 Reply to: Niklas Gustafsson Deon Brewis Herb Sutter Sana Mithani

More information

Homework 4. Any questions?

Homework 4. Any questions? CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible

More information

A Proposal to Add a Const-Propagating Wrapper to the Standard Library

A Proposal to Add a Const-Propagating Wrapper to the Standard Library Doc number: N4057 Revises: N3973 Date: 2014-07-02 Project: Programming Language C++, Library Evolution Working Group Reply-to: Jonathan Coe Robert Mill A Proposal

More information

Why Deprecating async() is the Worst of all Options

Why Deprecating async() is the Worst of all Options Doc No: WG21 N3780 Date: 2013-09-26 Reply to: Nicolai Josuttis (nico@josuttis.de) Subgroup: SG1 Concurrency Prev. Version: none Why Deprecating async() is the Worst of all Options The concurrency working

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 Introduction 2 IS 0020 Program Design and Software Tools Exception Handling Lecture 12 November 23, 200 Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually

More information

The C++ Standard Library

The C++ Standard Library The C++ Standard Library What every professional C++ programmer should know about the C++ standard library. Rainer This book is for sale at http://leanpub.com/cpplibrary-write This version was published

More information

POSIX Threads and OpenMP tasks

POSIX Threads and OpenMP tasks POSIX Threads and OpenMP tasks Jimmy Aguilar Mena February 16, 2018 Introduction Pthreads Tasks Two simple schemas Independent functions # include # include void f u n c t i

More information

A Standardized Representation of Asynchronous Operations

A Standardized Representation of Asynchronous Operations Document number: N3428=12-0118. Date: 2012-09-21 Reply-to: Niklas Gustafsson < niklas.gustafsson@microsoft.com> Artur Laksberg < arturl@microsoft.com> Herb Sutter < hsutter@microsoft.com> Sana Mithani

More information

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CORBA Programming with TAOX11. The C++11 CORBA Implementation CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy

More information

Distributed Real-Time Control Systems

Distributed Real-Time Control Systems Distributed Real-Time Control Systems Chapter 23 Additional C++ and Boost ASIO Features 1 Callable Objects 2 Function Objects Function objects (or Functors) are objects specifically designed to be used

More information

ECE Fall 2018, Test 3

ECE Fall 2018, Test 3 1 ECE 30862 Fall 2018, Test 3 DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST PAGE IS THE ANSWER SHEET. TEAR IT OFF AND PUT ALL ANSWERS THERE. TURN IN BOTH PARTS OF THE

More information

UEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class

UEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class UEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class What you will learn from Lab 6 In this laboratory, you will learn the advance topics of object-oriented programming using class.

More information

Multi-threaded Programming in C++

Multi-threaded Programming in C++ Multi-threaded Programming in C++ (2016/2017) Giuseppe Massari, Federico Terraneo giuseppe.massari@polimi.it federico.terraneo@polimi.it Outline 2/45 Introduction Multi-tasking implementations C++11 threading

More information

A Proposal to Add a Logical Const Wrapper to the Standard Library Technical Report

A Proposal to Add a Logical Const Wrapper to the Standard Library Technical Report Doc number: N3973 Date: 2014-05-12 Project: Programming Language C++, Library Evolution Working Group Reply-to: Jonathan Coe Robert Mill A Proposal to Add a Logical

More information

Parallelization, OpenMP

Parallelization, OpenMP ~ Parallelization, OpenMP Scientific Computing Winter 2016/2017 Lecture 26 Jürgen Fuhrmann juergen.fuhrmann@wias-berlin.de made wit pandoc 1 / 18 Why parallelization? Computers became faster and faster

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Error Handling and Exceptions Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de Summer

More information

Let s go straight to some code to show how to fire off a function that runs in a separate thread:

Let s go straight to some code to show how to fire off a function that runs in a separate thread: Introduction to C++11 Threads In C++11 a wrapper Thread class is available. However, you still need to have a library that implements the thread class. Visual Studio supports C++11 threads, but some other

More information

Introduction to modern C++

Introduction to modern C++ Introduction to modern C++ Olve Maudal C++ has evolved a lot since it was first introduced as "C with classes" with primitive support for object-oriented programming. In particular during the last 10-15

More information

Scientific Computing WS 2017/2018. Lecture 26. Jürgen Fuhrmann Lecture 26 Slide 1

Scientific Computing WS 2017/2018. Lecture 26. Jürgen Fuhrmann Lecture 26 Slide 1 Scientific Computing WS 2017/2018 Lecture 26 Jürgen Fuhrmann juergen.fuhrmann@wias-berlin.de Lecture 26 Slide 1 Lecture 26 Slide 2 Why parallelization? Computers became faster and faster without that...

More information

Why C++ is much more fun than C (C++ FAQ)?

Why C++ is much more fun than C (C++ FAQ)? From C to C++ Why C++ is much more fun than C (C++ FAQ)? 1. Classes & methods - OO design 2. Generic programming - Templates allow for code reuse 3. Stricter type system (e.g. function args) 4. Some run-time

More information

Distributed Programming

Distributed Programming Distributed Programming Lecture 02 - Processes, Threads and Synchronization Edirlei Soares de Lima Programs and Processes What is a computer program? Is a sequence

More information

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. C++ TEMPLATES http://www.tutorialspoint.com/cplusplus/cpp_templates.htm Copyright tutorialspoint.com Templates are the foundation of generic programming, which involves writing code in a way that is independent

More information

A Cooperatively Interruptible Joining Thread, Rev 2

A Cooperatively Interruptible Joining Thread, Rev 2 Project: ISO JTC1/SC22/WG21: Programming Language C++ Doc No: WG21 P0660R3 Date: 2018-05-07 Reply to: Nicolai Josuttis (nico@josuttis.de), Herb Sutter (hsutter@microsoft.com), Anthony Williams (anthony@justsoftwaresolutions.co.uk)

More information

C++ Pub Quiz. Sponsored by: Sponsored by: A 90 minute quiz session at ACCU Terrace Bar, Marriott Hotel, Bristol , April 10, 2014

C++ Pub Quiz. Sponsored by: Sponsored by: A 90 minute quiz session at ACCU Terrace Bar, Marriott Hotel, Bristol , April 10, 2014 C++ Pub Quiz Olve Maudal, feat Lars Gullik Sponsored by: Sponsored by: + + A 90 minute quiz session at ACCU Terrace Bar, Marriott Hotel, Bristol 1600-1730, April 10, 2014 Sponsored by NDC conferences:

More information

CS 3305 Intro to Threads. Lecture 6

CS 3305 Intro to Threads. Lecture 6 CS 3305 Intro to Threads Lecture 6 Introduction Multiple applications run concurrently! This means that there are multiple processes running on a computer Introduction Applications often need to perform

More information

Lecture 8. Exceptions, Constructor, Templates TDDD86: DALP. Content. Contents Exceptions

Lecture 8. Exceptions, Constructor, Templates TDDD86: DALP. Content. Contents Exceptions Lecture 8 Exceptions, Constructor, Templates TDDD86: DALP Utskriftsversion av Lecture in Data Structures, Algorithms and Programming Paradigms 19th September 2017 Ahmed Rezine, IDA, Linköping University

More information

Exception Handling Pearson Education, Inc. All rights reserved.

Exception Handling Pearson Education, Inc. All rights reserved. 1 16 Exception Handling 2 16.1 Introduction Exceptions Indicate problems that occur during a program s execution Occur infrequently Exception handling Can resolve exceptions Allow a program to continue

More information

Part X. Advanced C ++

Part X. Advanced C ++ Part X Advanced C ++ topics Philip Blakely (LSC) Advanced C++ 158 / 217 References The following are highly regarded books. They are fairly in-depth, and I haven t read them in their entirity. However,

More information

Resumable Functions. 1. The Problem

Resumable Functions. 1. The Problem Doc No: N3650 Supersedes: N3564 Date: 2013-05-02 Reply to: Niklas Gustafsson < niklas.gustafsson@microsoft.com> Deon Brewis < deonb@microsoft.com> Herb Sutter Sana Mithani

More information

Exceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions

Exceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions CS162: Introduction to Computer Science II A typical way to handle error conditions is through the return value. For example, suppose we create a loadfile() function that returns true if it loaded the

More information

S AMPLE CHAPTER IN ACTION. Practical Multithreading. Anthony Williams MANNING

S AMPLE CHAPTER IN ACTION. Practical Multithreading. Anthony Williams MANNING S AMPLE CHAPTER IN ACTION Practical Multithreading Anthony Williams MANNING C++ Concurrency in Action by Anthony Williams Chapter 2 Copyright 2012 Manning Publications brief contents 1 Hello, world of

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

Animation Part 2: MoveableShape interface & Multithreading

Animation Part 2: MoveableShape interface & Multithreading Animation Part 2: MoveableShape interface & Multithreading MoveableShape Interface In the previous example, an image was drawn, then redrawn in another location Since the actions described above can apply

More information

Scientific Computing WS 2018/2019. Lecture 23. Jürgen Fuhrmann Lecture 23 Slide 1

Scientific Computing WS 2018/2019. Lecture 23. Jürgen Fuhrmann Lecture 23 Slide 1 Scientific Computing WS 2018/2019 Lecture 23 Jürgen Fuhrmann juergen.fuhrmann@wias-berlin.de Lecture 23 Slide 1 Lecture 23 Slide 2 TOP 500 2018 rank 1-6 Based on linpack benchmark: solution of dense linear

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 19 November 7, 2018 CPSC 427, Lecture 19, November 7, 2018 1/18 Exceptions Thowing an Exception Catching an Exception CPSC 427, Lecture

More information

C++ Programming Lecture 11 Software Engineering Group

C++ Programming Lecture 11 Software Engineering Group C++ Programming Lecture 11 Software Engineering Group Philipp D. Schubert Contents 1. High performance computing 2. High performance computing in C++ 1. std::thread 2. std::future 3. std::async 4. std::future

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Futures. Prof. Clarkson Fall Today s music: It's Gonna be Me by *NSYNC

Futures. Prof. Clarkson Fall Today s music: It's Gonna be Me by *NSYNC Futures Prof. Clarkson Fall 2017 Today s music: It's Gonna be Me by *NSYNC Review Previously in 3110: Functional programming Modular programming Interpreters Formal methods Final unit of course: Advanced

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

Working with Batches of Data

Working with Batches of Data Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html 2 Abstract So far we looked at simple read a string print a string problems. Now we will look at more complex problems

More information

Programming C++ Lecture 6. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor

Programming C++ Lecture 6. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Programming C++ Lecture 6 Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Friends 2 Friends of Objects S Classes sometimes need friends. S Friends are defined outside

More information

A Crash Course in (Some of) Modern C++

A Crash Course in (Some of) Modern C++ CMPT 373 Software Development Methods A Crash Course in (Some of) Modern C++ Nick Sumner wsumner@sfu.ca With material from Bjarne Stroustrup & Herb Sutter C++ was complicated/intimidating Pointers Arithmetic

More information

CSE 160 Lecture 7. C++11 threads C++11 memory model

CSE 160 Lecture 7. C++11 threads C++11 memory model CSE 160 Lecture 7 C++11 threads C++11 memory model Today s lecture C++ threads The C++11 Memory model 2013 Scott B. Baden / CSE 160 / Winter 2013 2 C++11 Threads Via , C++ supports a threading

More information

The C++ Memory Model. Rainer Grimm Training, Coaching and Technology Consulting

The C++ Memory Model. Rainer Grimm Training, Coaching and Technology Consulting The C++ Memory Model Rainer Grimm Training, Coaching and Technology Consulting www.grimm-jaud.de Multithreading with C++ C++'s answers to the requirements of the multicore architectures. A well defined

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

BYOD - WEEK 3 AGENDA. Dictionary Encoding. Organization. Sprint 3

BYOD - WEEK 3 AGENDA. Dictionary Encoding. Organization. Sprint 3 WEEK 3 BYOD BYOD - WEEK 3 AGENDA Dictionary Encoding Organization Sprint 3 2 BYOD - WEEK 3 DICTIONARY ENCODING - MOTIVATION 3 Memory access is the new bottleneck Decrease number of bits used for data representation

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Advanced Programming C# Lecture 13. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 13. dr inż. Małgorzata Janik Advanced Programming C# Lecture 13 dr inż. Małgorzata Janik majanik@if.pw.edu.pl Winter Semester 2017/2018 Project C# 2017/2018, Lecture 13 3 / 24 Project part III Final Date: 22.01.2018 (next week!) Today

More information

Modern and Lucid C++ Advanced for Professional Programmers. Part 7 Compile-Time Computation. Department I - C Plus Plus

Modern and Lucid C++ Advanced for Professional Programmers. Part 7 Compile-Time Computation. Department I - C Plus Plus Department I - C Plus Plus Modern and Lucid C++ Advanced for Professional Programmers Part 7 Compile-Time Computation Thomas Corbat / Prof. Peter Sommerlad Rapperswil, 23.02.2017 HS2017 Topics 2 SFINAE

More information

Software Transactional Memory Pure functional approach

Software Transactional Memory Pure functional approach Software Transactional Memory Pure functional approach Alexander Granin graninas@gmail.com C++ Russia 2018, Saint Petersburg struct Presentation Introduction1 Functional programming in C++ Introduction2

More information