Concurrency Abstractions in C#

Similar documents
Concurrency Abstractions in C#

Concurrency Abstractions in C#

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

Implementing Joins using Extensible Pattern Matching

What should we do with this freedom?

Assertions, pre/postconditions

A Deterministic Concurrent Language for Embedded Systems

Global shared variables. Message passing paradigm. Communication Ports. Port characteristics. Sending a message 07/11/2018

A Deterministic Concurrent Language for Embedded Systems

Embedded Systems 8. Identifying, modeling and documenting how data moves around an information system. Dataflow modeling examines

CSE 153 Design of Operating Systems

A Deterministic Concurrent Language for Embedded Systems

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

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

Concurrent programming: From theory to practice. Concurrent Algorithms 2015 Vasileios Trigonakis

Synchronization Principles II

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

Concurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency.

SCHOOL: a Small Chorded Object-Oriented Language

Outline. Monitors. Barrier synchronization The sleeping barber problem Readers and Writers One-way tunnel. o Monitors in Java

Actor-Based Concurrency: Implementation and Comparative Analysis With Shared Data and Locks Alex Halter Randy Shepherd

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

First Name: Last: ID# 1. Hexadecimal uses the symbols 1, 2, 3, 4, 5, 6, 7 8, 9, A, B, C, D, E, F,G.

Threads and Parallelism in Java

CSE 153 Design of Operating Systems Fall 2018

Asynchronous Functions in C#

CS533 Concepts of Operating Systems. Jonathan Walpole

C# Asynchronous Programming Model

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

Models and languages of concurrent computation

Enforcing Mutual Exclusion Using Monitors

CSE 120 Principles of Operating Systems Spring 2016

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

Haskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder

CmpSci 187: Programming with Data Structures Spring 2015

1 Lexical Considerations

CS111: PROGRAMMING LANGUAGE II

wait with priority An enhanced version of the wait operation accepts an optional priority argument:

CSE 153 Design of Operating Systems

Pace University. Fundamental Concepts of CS121 1

Chapter 6: Process Synchronization

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

Operational Semantics of Cool

Synchronization 1. Synchronization

Programming Safe Agents in Blueprint. Alex Muscar University of Craiova

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

JAVA BYTE IPC: PART 1 DERIVING NIO FROM I/O. Instructor: Prasun Dewan (FB 150,

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

Computer Aided Verification 2015 The SPIN model checker

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

Parallel And Distributed Compilers

Lecture 5: Synchronization w/locks

Introduction to C# Applications

Semaphores INF4140. Lecture 3. 0 Book: Andrews - ch.04 ( ) INF4140 ( ) Semaphores Lecture 3 1 / 34

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Dept. of CSE, York Univ. 1

Declarative Concurrency (CTM 4)

Dataflow Languages. Languages for Embedded Systems. Prof. Stephen A. Edwards. March Columbia University

Synchronization II: EventBarrier, Monitor, and a Semaphore. COMPSCI210 Recitation 4th Mar 2013 Vamsi Thummala

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

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)

Chapter 13. Concurrency ISBN

Deterministic Concurrency

CS 450 Exam 2 Mon. 11/7/2016

Structuring the Computation. Structuring the Computation

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Lecture 8: Threads. Lisa (Ling) Liu

Objectives. Introduce static keyword examine syntax describe common uses

Multiple Inheritance. Computer object can be viewed as

Concept of a process

Lecture 6 (cont.): Semaphores and Monitors

Chapter Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify

CHAPTER 6: PROCESS SYNCHRONIZATION

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

There are 8 total numbered pages, 6 Questions. You have 60 minutes. Budget your time carefully!

Lecture 8: September 30

Shared Memory Programming. Parallel Programming Overview

CS3733: Operating Systems

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

Today: Distributed Objects. Distributed Objects

Concurrency and Synchronisation

Pierce Ch. 3, 8, 11, 15. Type Systems

The Java Memory Model

Concurrency and Synchronisation

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Problems with Concurrency. February 19, 2014

async and ~future (Revision 3)

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.

Synchronization I. Jo, Heeseung

Concurrent Programming. CS105 Programming Languages Supplement

Lexical Considerations

7. System Design: Addressing Design Goals

Erlang 101. Google Doc

Concurrent Programming using Threads

Declarative concurrency. March 3, 2014

Transcription:

Concurrency Abstractions in C# Concurrency critical factor in behavior/performance affects semantics of all other constructs advantages of language vs. library compiler analysis/optimization clarity of syntax asynchronous communication occurs at various levels requires language support 1

Syntax: Basic Constructs Asynchronous Methods async postevent (EventInfo data) { // method body using data calls to async methods return immediately method body scheduled for execution in another thread no return result similar to sending message/event 2

Example: Basic Constructs - Chords public class Buffer { public string Get() & public async Put (string s) { return s; illustrates a single chord with two methods chord body is executed only when all methods in the chord have been called non-async method call implicitly blocked/queued until chord complete async method calls are queued until matched (caller not blocked) at most one non-async method per chord non-deterministic selection of method calls matched by chord chord body executes in thread of non-async caller (unless all methods in chord are async methods, in which case a new thread is created) 3

Executing Chords invocation queues (one per method) methods [a] [b] [c] bitmaps [a] [b] (one per chord) [b] [c] execute [a,b] chord execute [b.c] chord 4

Counting via Methods class Token public Token (int initial_tokens) { for (int i=0; i < initial_tokens; i++) Release(); public int Grab (int id) & public async Release() { return id; allows clients to Grab and Release a limited number of tokens argument on Grab returned to client 5

Recording State via Methods public class OneCell { public OneCell() {empty(); public void Put(object o) & private async empty() { contains ( o ); public object Get() & private async contains (object o) { empty(); returns o; methods empty and contains are declared private methods empty and contains carries the state of the cell 6

Reader-Write Example class ReaderWriter { ReaderWriter () { idle(); public void Shared () & async idle() { s(1); public void Shared() & async s(int n) { s(n+1); public void ReleaseShared() &asyncs(int n) { if (n == 1) idle(); else s(n-1); public void Exclusive() & async idle() { public void ReleaseExclusive() { idle(); 7

Active Object (Actor): Base Class public abstract class ActiveObject { protected bool done; abstract protected void ProcessMessage(); public ActiveObject() { done = false; mainloop(); async mainloop() { while(!done) {ProcessMessage(); actor: thread per object; repeatedly processes received messages note: thread created by call to async mainloop() abstract class creates basic actor infrastructure/pattern 8

Active Object (Actor): Event Example 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) public async CloseDown() & override protected void ProcessMessage() { done = true; message reception/processing driven by ProcessMessage invocations in mainloop 9

Implementation Outline chord async method with argument(s) of type m async method with no arguments synchronous method bitmap, one bit for each method in the chord mq: to hold message (e.g., intq) voidq: a counter threadq: for blocking caller threads 10

Performance Benchmark Test operations/sec (thousands) polyphonic non-polyphonic ping pong 115 240 single processor bounded buffer 682 115 (1 prod/1 cons) bounded buffer 423 118 (2 prod/2 cons) ping pong 66 70 dual processor bounded buffer (1 prod/1 cons) bounded buffer (2 prod/2 cons) 288 250 125 42 11

class ReaderWriter { async idle(); async s(int); Syntactic Extension ReaderWriter() { idle(); public void Shared() when idle() {s(1); when s(int n) { s(n+1); public void ReleaseShared() when s(int n) { if (n ==1) idle(); else s(n-1); public void Exclusive() when idle() { public void ReleaseExclusive() { idle (); 12