Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.

Slides:



Advertisements
Similar presentations
1 Polyphonic C# Nick Benton Luca Cardelli Cédric Fournet Microsoft Research.
Advertisements

1 Polyphonic C# Nick Benton Luca Cardelli Cédric Fournet Microsoft Research.
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
1 Chapter Three Using Methods. 2 Objectives Learn how to write methods with no arguments and no return value Learn about implementation hiding and how.
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Road Map Introduction to object oriented programming. Classes
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Encapsulation by Subprograms and Type Definitions
CS 201 Functions Debzani Deb.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Modern Concurrency Abstractions for C# Advanced Software Tools Seminar December, 2004 presented by: Guy Gueta.
Chapter 10 Classes Continued
IT PUTS THE ++ IN C++ Object Oriented Programming.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
What is Concurrent Programming? Maram Bani Younes.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Inheritance in the Java programming language J. W. Rider.
Chords in C#. Introduction Polyphonic C# is an extension to the C# language Extension is aimed at providing in-language concurrency support CS 5204 –
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Chapter 7 Templates. Objectives Introduction Function Templates Class Templates Standard Template Library.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
CS212: Object Oriented Analysis and Design
SPL/2010 Synchronization 1. SPL/2010 Overview ● synchronization mechanisms in modern RTEs ● concurrency issues ● places where synchronization is needed.
Object Oriented Programming
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Introduction to Object-Oriented Programming Lesson 2.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
1 Concurrency Abstractions in C#. Concurrency in C# CS 5204 – Fall, Motivation Concurrency critical factor in behavior/performance affects semantics.
Exceptions in the Java programming language J. W. Rider.
Sections Inheritance and Abstract Classes
Java Primer 1: Types, Classes and Operators
Methods Attributes Method Modifiers ‘static’
Review: Two Programming Paradigms
CS212: Object Oriented Analysis and Design
Monitors Chapter 7.
Chapter 6 Methods: A Deeper Look
Packages and Interfaces
Multithreading.
Monitors Chapter 7.
Monitors Chapter 7.
Classes, Objects and Methods
C++ Object Oriented 1.
SPL – PS3 C++ Classes.
Threads and concurrency / Safety
Presentation transcript:

Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research

Outline Introduction Polyphonic C# overview Specification Programming in Polyphonic C# Related work Future work Conclusion

Introduction How is concurrency implemented ? Language feature Libraries Provides features like – memory management & exceptions Advantages of having them as language features Produce better code Warn programmers of potential & actual problems

They made concurrency as a language feature Monitors - more asynchronous Shift in focus – shared memory to event- or message- oriented concurrency Programming constructs handling asynchronous communication Polyphonic C#

Polyphonic C# Overview Extension to C# - new asynchronous concurrency constructs based on join calculus New constructs – Asynchronous methods Chords Asynchronous methods – guaranteed to complete essentially immediately Never returns a result async keyword is used

Chord – consists of a header and a body Header - set of method declarations Body is only executed once all the methods in the header have been called Method calls are implicitly queued up until/unless there is a matching chord If buff is instance of Buffer then call to buff.Get() has two possibilities If there has previously been an unmatched call to buff.Put(s) If there are no previous unmatched calls to buff.Put(s)

Conversely - call to the asynchronous method buff.Put(s) has two possibilities If there has previously been an unmatched call to buff.Get() If there are no pending calls to buff.Get() Exactly which pairs of calls are matched up is unspecified Difficulties In which thread the body runs ? To which method call the final value is returned ?

Specification If return-type is async then the formal parameter list formals may not contain any ref or out parameter modifier At most one method-header may have a non-async return- type. If the chord has a method-header with return-type type, then body may use return statements with type expressions, otherwise body may use empty return statements. All the formals appearing in method-headers must have distinct identifiers. Two method-headers may not have both the same member- name and the same argument type signature.

The method-headers must either all declare instance methods or all declare static methods All method-headers with the same member-name and argument type signature must have the same return- type and identical sets of attributes and modifiers Typing issues – async is a subtype of void an async method may override a void one, a void delegate may be created from an async method, and an async method may implement a void method in an interface

Programming Polyphonic C# A simple example Put Chord Get Chord

Reader writer lock Problems with the above code Fairness problem – starvation(writer)

Reader Writer lock

Combining Asynchronous Messages

Active Objects

Implementation Translation from Polyphonic C# to plain C# Converting state chords to state automata synchronization state consists of the pending calls threads for regular methods messages for asynchronous methods synchronization depends on – presence or absence of pending calls number of calls actual parameters

Performance issues – Complete asynchronous chord is always expensive asynchronous method synchronous method All asynchronous messages are present Otherwise Translation – modularize the translated code by introducing auxiliary classes for queues and bitmasks Queues – class that represents message queues

Related work The work is based on join calculus Join java follows similar approach of using join calculus Synchronization barriers in dataflow languages modeled in Petrinets are similar to chords.

Future Work Scope for optimizing the implementation Lock optimization - There are situations when we could safely ‘fuse’ successive critical sections protected by the same lock. Queue optimization - at most one pending call on a particular object could be compiled using private fields instead of queues Thread optimization - Purely asynchronous chords can often be compiled to run in the invoking thread, rather than a new one

Conclusion Designed and implemented a join calculus-based extension of C# that is simple, expressive, and efficient. Writing correct concurrent programs is considerably less difficult in Polyphonic C# than in ordinary C# Implementation is constrained by the underlying threads-and-locks model

QUESTIONS