Polyphonic C# is an extension to the C# language Extension is aimed at providing in-language concurrency support

Similar documents
Concurrency Abstractions in C#

Concurrency Abstractions in C#

Concurrency Abstractions in C#

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

DAD Lab. 2 Additional C# Topics

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

! Operators such as =, +, <, can be defined to. ! The function names are operator followed by the. ! Otherwise they are like normal member functions:

Assertions, pre/postconditions

Common Misunderstandings from Exam 1 Material

CSCE 110 PROGRAMMING FUNDAMENTALS

CS313D: ADVANCED PROGRAMMING LANGUAGE

1 Lexical Considerations

Rules and syntax for inheritance. The boring stuff

C++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator

Introduction to Programming Using Java (98-388)

The Basic Parts of Java

CSE 143. Linked Lists. Linked Lists. Manipulating Nodes (1) Creating Nodes. Manipulating Nodes (3) Manipulating Nodes (2) CSE 143 1

C++ Templates. David Camp

Example Final Questions Instructions

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Lexical Considerations

Classes and Objects. Class scope: - private members are only accessible by the class methods.

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

CS32 - Week 1. Umut Oztok. June 24, Umut Oztok CS32 - Week 1

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Motivation was to facilitate development of systems software, especially OS development.

Chapter 4 Defining Classes I

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the

Do not start the test until instructed to do so!

Lexical Considerations

CSI33 Data Structures

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

class Polynomial { public: Polynomial(const string& N = "no name", const vector<int>& C = vector<int>());... };

Documenting Advanced Programming Techniques

CS111: PROGRAMMING LANGUAGE II

Motivation was to facilitate development of systems software, especially OS development.

Practice for Chapter 11

CS11 Introduction to C++ Fall Lecture 7

Binary Search Trees Part Two

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

PRACTICE MIDTERM EXAM #2

Test 1: CPS 100. Owen Astrachan. October 1, 2004

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12

PIC 10A. Lecture 17: Classes III, overloading

Final CSE 131B Spring 2004

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming

Principles of Object Oriented Programming. Lecture 4

CS 161 Exam II Winter 2018 FORM 1

CSE 303: Concepts and Tools for Software Development

Outline. Why do we write functions? Introduction to Functions. How do we write functions? Using Functions. Introduction to Functions March 21, 2006

Week 4, Wednesday (Spring 2015). Dr. Yoder. Sec 051. Page 1 of 5

The Composite State Visitor Pattern

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Implementing a List in Java. CSE 143 Java. Just an Illusion? List Interface (review) Using an Array to Implement a List.

Assignment of Objects

Implementing Abstract Data Types (ADT) using Classes

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

EMBEDDED SYSTEMS PROGRAMMING More About Languages

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

C#: framework overview and in-the-small features

Introduction to C# Applications

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

public class TicketMachine Inner part omitted. public class ClassName Fields Constructors Methods

List ADT. Announcements. The List interface. Implementing the List ADT

Topic 7: Algebraic Data Types

C++_ MARKS 40 MIN

COMP6771 Advanced C++ Programming

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

Topic 5 Polymorphism. " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.

6.096 Introduction to C++ January (IAP) 2009

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

Tokens, Expressions and Control Structures

Functions. Lecture 6 COP 3014 Spring February 11, 2018

SCHOOL: a Small Chorded Object-Oriented Language

Implementing a List in Java. CSE 143 Java. List Interface (review) Just an Illusion? Using an Array to Implement a List.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Macros and Preprocessor. CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang

CS 247: Software Engineering Principles. ADT Design

CS 61C: Great Ideas in Computer Architecture Introduction to C

Introduction to C++ Systems Programming

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes

Object Oriented Programming in C#

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

G52CPP C++ Programming Lecture 9

Today s Agenda. Quick Review

EECS168 Exam 3 Review

Instantiation of Template class

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

The Decaf Language. 1 Lexical considerations

Agenda. Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections

Transcription:

Introduction Polyphonic C# is an extension to the C# language Extension is aimed at providing in-language concurrency support Agenda: 1.Extension Syntax 2.Rules 3.How it works 4.Translation of new constructs to traditional C# 5.An example (Stock Server : Active Object)

New Syntax No return: Just schedule this method for execution in another thread async methodname(argumenttype stuff) { //stuff to do

New Syntax Method Declaration1 Method Declaration 2 public int Grab(int id) & public async Release() { //Method body Chord Separator Chord body executes when all of the methods in the header have been called

Syntax Rules Method Declarations Chords in C# ref and out parameter modifiers cannot be used in async methods because by the time this method is executed, who knows what the caller is doing? async method(out int i) { //stuff

Syntax Rules Chord Declarations Chords in C# Only one synchronous method is allowed in a chord declaration. Otherwise, in which thread is the body executed? This decision could have behavioral effects. async put(int i) &void get()&void calculate() { //stuff

Syntax Rules Chord Declarations Chords in C# If a method header has a return value, the body can return a value of that type. If no type is provided then an empty return statement can be used. int get() & async trigger() { return 4; Matching Types

Syntax Rules Chord Declarations Chords in C# All formals appearing in method-headers must have distinct identifiers. Otherwise, there would be translation issues we ll see how chords are translated into conventional C# later! void get(int i) & async calculate(int i) { //stuff

Syntax Rules Chord Declarations Chords in C# Two method headers within the same chord declaration may not have both the same method name and argument types. Otherwise, which function to call at runtime? void set(int i) & async set(int k) { //stuff

Syntax Rules Chord Declarations Chords in C# All method headers within a chord declaration must be either instance declarations or static declaration: Never a mix. static void work(int i) & async set(int k) { //stuff

Syntax Rules Within a Class Chords in C# 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. class c { string work(int i) & async set(int k) { //stuff int work (int i) & async set(int k){ //stuff

Syntax Rules Within a Class Chords in C# When methods are overridden, all their chords must also be completely overridden. class C { virtual void f() & virtual async g() {/*stuff1*/ virtual void f() & virtual async h() {/*stuff2*/ class D:C { override async g() {/*stuff3*/ WRONG override void f() & override async g(){/*new stuff 1*/ override void f() & override async h(){/*new stuff2*/ Correct!

Thread B Chord Methodology class token { public Token(int initial_tokens) { for(int i = 0; i < initial_tokens; i++)release(); Thread A Grab() public int Grab(int id) & public async Release() { return id; class token { Release() public Token(int initial_tokens) { for(int i = 0; i < initial_tokens; i++)release(); public int Grab(int id) & public async Release() { return id; 01 Scan 01

Chord Translation - BitMask struct BitMask { private int v ; // = 0; public void set(int m) { v = m; public void clear(int m) { v &= m; public bool match(int m) { return ( v & m)==0;

Chord Translation - VoidQ class voidq { private int n; public voidq(){ n = 0; public void add() {n++; public void get() {n--; public bool empty {get{return n==0;

Chord Translation - ThreadQ class threadq { private bool signalled = false; private int count = 0; public bool empty {get{return count == 0; public void yield(object mycurrentlock){ count++; Monitor.Exit(myCurrentLock); lock(this){ while(!signaled) Monitor.Wait(this); signaled = false; Monitor.Enter(myCurrentLock); count--; public void wakeup(){ lock(this){ signaled = true; Monitor.Pulse(this);

Chord Translation Token Example Class Variables Scan method Tokens constructor (see polyphonic code) Release method Grab method class Token { private const int mgrab = 1 << 0; private const int mrelease = 1 << 1; private threadq GrabQ = new threadq(); private voidq ReleaseQ = new voidq(); private const int mgrabrelease = mgrab mrelease; private BitMask s = new BitMask(); private object mlock = ReleaseQ; private void scan() { if (s.match(mgrabrelease)) {GrabQ.wakeup(); return; public Token(int initial tokens) { for (int i = 0; i < initial tokens ; i++) Release(); [OneWay] public void Release() { lock(mlock) { ReleaseQ.add(); if (! s.match(mrelease)) { s.set (mrelease); scan (); public int Grab(int id) { Monitor.Enter(mlock); if (! s.match(mgrab)) goto now; later : GrabQ.yield(mlock); if (GrabQ.empty) s.clear(mgrab); now: if (s.match(mrelease)) { ReleaseQ.get (); if (ReleaseQ.empty) s.clear(mrelease); scan(); Monitor.Exit(mlock); { return id; // source code for the chord else{ s.set (mgrab); goto later ;

Example (From Paper) public abstract class ActiveObject { protected bool done; abstract protected void ProcessMessage(); public ActiveObject(){ done = false; mainloop(); async mainloop(){ while (!done){ ProcessMessage(); public class StockServer:ActiveObject{ private ArrayList clients = new ArrayList(); public async AddClient(Client c) && override protected void ProcessMessage(){ clients.add(c); public async WireQuote(Quote q) & override protected void ProcessMessage(){ foreach(client c in clients){ c.updatequote(q);