1 Concurrency Abstractions in C#. Concurrency in C# CS 5204 – Fall, 2008 2 Motivation Concurrency critical factor in behavior/performance affects semantics.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

© 2006 Microsoft Corporation. All rights reserved. The Joins Concurrency Library Cω in a Box Claudio Russo Microsoft Research, Cambridge
1 Polyphonic C# Nick Benton Luca Cardelli Cédric Fournet Microsoft Research.
1 Polyphonic C# Nick Benton Luca Cardelli Cédric Fournet Microsoft Research.
Operating Systems Lecture 7.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 10: Advanced Object-Oriented Mechanisms (based on.
Ch 7 B.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania Fall 2003 Lecture Note 2.6: Message-Based Communication.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Concurrency (3) CSE 132. iClicker/WUTexter Question The following four numbers are in 8-bit 2’s complement form: Which.
Introduction in algorithms and applications Introduction in algorithms and applications Parallel machines and architectures Parallel machines and architectures.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Monitors CSCI 444/544 Operating Systems Fall 2008.
Modern Concurrency Abstractions for C# Advanced Software Tools Seminar December, 2004 presented by: Guy Gueta.
Department of Computer Science Presenters Dennis Gove Matthew Marzilli The ATOMO ∑ Transactional Programming Language.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
University of Pennsylvania 9/28/00CSE 3801 Concurrent Programming (Critical Regions, Monitors, and Threads) CSE 380 Lecture Note 6 Insup Lee.
Monitor  Giving credit where it is due:  The lecture notes are borrowed from Dr. I-Ling Yen at University of Texas at Dallas  I have modified them and.
Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.
May 6, ICE 1341 – Programming Languages (Lecture #19) In-Young Ko Programming Languages (ICE 1341) Lecture #19 Programming Languages (ICE 1341)
Advanced Synchronization Constructs Related Work: Monitors: An Operating System Structuring, C.A.R Hoare (developing on Brinch Hansen’s concepts) Synchronization.
Austin Java Users Group developerWorks article – µActor Library BARRY FEIGENBAUM, PH. D. 02/26/13.
Concurrency (Based on:Concepts of Programming Languages, 8th edition, by Robert W. Sebesta, 2007)
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
Chords in C#. Introduction Polyphonic C# is an extension to the C# language Extension is aimed at providing in-language concurrency support CS 5204 –
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
Threads and Thread Control Thread Concepts Pthread Creation and Termination Pthread synchronization Threads and Signals.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Denis Caromel1 Institut universitaire de France (IUF) INRIA Sophia-Antipolis – CNRS – I3S – Université de Nice Luis Mateu DCC – Universidad de Chile Eric.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Synchronization Methods in Message Passing Model.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-4 Process Communication Department of Computer Science and Software.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Fall 2008Programming Development Techniques 1 Topic 20 Concurrency Section 3.4.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Synchronicity II Introduction to Operating Systems: Module 6.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Compiler Design Lecture 10 Semantic Analysis. int aintegers int a[2][3]array(2, array(3, integer)) int f(int, float, char) int x float x char  int Int.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Concurrency/synchronization using UML state models November 27th, 2007 Michigan State University.
Case Study: Pthread Synchronization Dr. Yingwu Zhu.
Tom Van Cutsem, Vrije Universiteit Brussel
Principles of programming languages 12: Functional programming
“Language Mechanism for Synchronization”
Java Primer 1: Types, Classes and Operators
Chapter 5: Process Synchronization (Con’t)
12 Asynchronous Programming
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Conditional Statements
Semaphore Originally called P() and V() wait (S) { while S <= 0
Background and Motivation
Chapter 30 Condition Variables
Subject : T0152 – Programming Language Concept
Monitor Giving credit where it is due:
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
Presentation transcript:

1 Concurrency Abstractions in C#

Concurrency in C# CS 5204 – Fall, Motivation 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

Concurrency in C# CS 5204 – Fall, Basic Constructs – Asynchronous Methods Syntax : async postEvent (EventInfo data) { // method body using data } calls to async method return “immediately” method body is scheduled for execution in another thread no return result is possible similar to sending message/event

Concurrency in C# CS 5204 – Fall, Basic Constructs - Chords Example: 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 completes 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)

Concurrency in C# CS 5204 – Fall, Executing Chords invocation queues (one per method) methods bitmaps (one per chord) [a][b] [c][b] [a][b][c]... execute [a,b] chord execute [b,c] chord

Concurrency in C# CS 5204 – Fall, “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

Concurrency in C# CS 5204 – Fall, 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

Concurrency in C# CS 5204 – Fall, Reader-Writer 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() & async s(int n) { if (n == 1) idle(); else s(n-1); } public void Exclusive() & async idle() {} public void ReleaseExclusive() { idle(); } }

Concurrency in C# CS 5204 – Fall, 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 pattern

Concurrency in C# CS 5204 – Fall, 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 protect void ProcessMessage() { done = true; } } message reception/processing driven by ProcessMessage invocations in mainLoop

Concurrency in C# CS 5204 – Fall, Implementation Outline chord bitmap, one bit for each method in the chord async method with argument(s) of type m mQ: to hold message (e.g., intQ for integers) async methods with no argument(s) voidQ: a counter synchronous method threadQ: for blocking caller threads

Concurrency in C# CS 5204 – Fall, Performance BenchmarkTest operations/sec (thousands) polyphonicnon-polyphonic single processor ping pong bounded buffer (1 prod/1 cons) bounded buffer (2 prod/2 cons) dual processor ping pong6670 bounded buffer (1 prod/1 cons) bounded buffer (2 prod/2 cons) 12542

Concurrency in C# CS 5204 – Fall, Syntactic Extension class ReaderWriter { async idle(); async s(int); 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 Exlcusive() when idle() {} public void ReleaseExclusive() { idle(); } }