The F# Team Microsoft

Size: px
Start display at page:

Download "The F# Team Microsoft"

Transcription

1 The F# Team Microsoft

2 Asynchronous and Parallel Programming with F# Workflows Some other F# Language Oriented Programming Techniques Lots of Examples

3 F# is: F# is a.net programming language Functional Imperative Object Oriented

4 Emphasis is on what is to be computed not how it happens Data is immutable by default Ability to express higher-order functions

5 Side effects Ability to declare and mutate variables Control flow (while, for, if, etc.)

6 Classes and Structs Polymorphism and Inheritance Events Succinct, type-inferred classes

7

8 Concurrent programming with shared state can be hard

9 Concurrent: Parallel: Multiple threads of execution These execute simultaneously Asynchronous: Computations that complete "later" Reactive: Waiting and responding is normal

10 To get 50 web pages in parallel? To get from thread to thread? To create a worker thread that reads messages? To handle failure on worker threads?

11 let ProcessImages() = Async.Run (Async.Parallel [ for i in 1.. numimages -> ProcessImage(i) ])

12 let task = async {... do! SwitchToNewThread()... do! SwitchToThreadPool()... do! SwitchToGuiThread()... }

13 OS Threads System.Threading.NET Thread Pool Parallel Extensions for.net

14 Target: make it easy to use Begin/End operations Stream.BeginRead :... Stream.EndRead : IAsyncResult *...

15 Typical Control Flow Compositional threadhopping? BeginRead EndRead Rest of Task

16 ReadAsync Rest of Task

17 Async.Parallel [ async { -> 2*2 + 3*6 }; async { -> } ] Compute 22 and 7 in parallel Async.Parallel [WebRequest.Async " WebRequest.Async " WebRequest.Async " ] Get these three web pages and wait until all have come back let pararrmap f (arr: _[]) = Async.Run (Async.Parallel [ for x in arr -> async { -> f x } ]) Naive Parallel Array Map

18

19 using System; using System.IO; using System.Threading; public static void ReadInImageCallback(IAsyncResult asyncresult) { public static void ProcessImagesInBulk() ImageStateObject state = (ImageStateObject)asyncResult.AsyncState; { public class BulkImageProcAsync { Stream stream = state.fs; int bytesread = stream.endread(asyncresult); Console.WriteLine("Processing images... "); long t0 = Environment.TickCount; public const String ImageBaseName = "tmpimage-"; if (bytesread!= numpixels) NumImagesToFinish = numimages; public const int numimages = 200; throw new Exception(String.Format AsyncCallback readimagecallback = new public const int numpixels = 512 * 512; ("In ReadInImageCallback, got the wrong number of " + AsyncCallback(ReadInImageCallback); "bytes from the image: {0}.", bytesread)); for (int i = 0; i < numimages; i++) // ProcessImage has a simple O(N) loop, and ProcessImage(state.pixels, you can vary the number state.imagenum); // of times you repeat that loop to make the stream.close(); application more CPU- // bound or more IO-bound. { ImageStateObject state = new ImageStateObject(); state.pixels = new byte[numpixels]; public static int processimagerepeats = 20; // Now write out the image. state.imagenum = i; // Using asynchronous I/O here appears not to be best practice. // Very large items are read only once, so you can make the // Threads must decrement NumImagesToFinish, // It and ends protect up swamping the threadpool, because the threadpool // buffer on the FileStream very small to save memory. // their access to it through a mutex. // threads are blocked on I/O requests that were just queued tofilestream fs = new FileStream(ImageBaseName + i + ".tmp", public static int NumImagesToFinish = numimages; // the threadpool. FileMode.Open, FileAccess.Read, FileShare.Read, 1, public static Object[] NumImagesMutex = new FileStream Object[0]; fs = new FileStream(ImageBaseName + state.imagenum true); + // WaitObject is signalled when all image processing ".done", is FileMode.Create, done. FileAccess.Write, FileShare.None, state.fs = fs; public static Object[] WaitObject = new Object[0]; 4096, false); fs.beginread(state.pixels, 0, numpixels, readimagecallback, public class ImageStateObject fs.write(state.pixels, 0, numpixels); state); { fs.close(); } public byte[] pixels; public int imagenum; // This application model uses too much memory. } public let ProcessImageAsync FileStream fs; () = // Releasing memory as soon as possible is a good idea, async { let instream = File.OpenRead(sprintf // especially global "Image%d.tmp" state. i) let! pixels = instream.readasync(numpixels) state.pixels = null; let pixels' = TransformImage(pixels,i) fs = null; let outstream = File.OpenWrite(sprintf // Record that an "Image%d.done" image is finished i) now. do! outstream.writeasync(pixels') lock (NumImagesMutex) do Console.WriteLine "done!" { } NumImagesToFinish--; let ProcessImagesAsyncWorkflow() = if (NumImagesToFinish == 0) Async.Run (Async.Parallel { [ for i in 1.. numimages -> Monitor.Enter(WaitObject); ProcessImageAsync i ]) Monitor.Pulse(WaitObject); Monitor.Exit(WaitObject); } } } } } // Determine whether all images are done being processed. // If not, block until all are finished. bool mustblock = false; Processing 200 images in parallel lock (NumImagesMutex) { if (NumImagesToFinish > 0) mustblock = true; } if (mustblock) { Console.WriteLine("All worker threads are queued. " + " Blocking until they complete. numleft: {0}", NumImagesToFinish); Monitor.Enter(WaitObject); Monitor.Wait(WaitObject); Monitor.Exit(WaitObject); } long t1 = Environment.TickCount; Console.WriteLine("Total time processing images: {0}ms", (t1 - t0));

20 Equivalent F# code (same perf) Open the file, synchronousl y Read from the file, asynchronously let ProcessImageAsync(i) = This object coordinates async { use instream = File.OpenRead(sprintf "source%d.jpg" i) let! pixels let = instream.readasync(numpixels) pixels' = TransformImage(pixels,i) use outstream = File.OpenWrite(sprintf "result%d.jpg" i) do! outstream.writeasync(pixels') do Console.WriteLine "done!" } let ProcessImagesAsync() = Async.Run (Async.Parallel! = asynchronous Write the result, asynchronously [ for i in 1.. numimages -> ProcessImageAsync(i) ]) Generate the tasks and queue them in parallel

21 using System; using System.IO; using System.Threading; public class BulkImageProcAsync Stream stream = state.fs; { int bytesread = stream.endread(asyncresult); public const String ImageBaseName = "tmpimage-"; if (bytesread!= numpixels) public const int numimages = 200; throw new Exception(String.Format public const int numpixels = 512 * 512; "bytes from the image: {0}.", bytesread)); // ProcessImage has a simple O(N) loop, and ProcessImage(state.pixels, you can vary the number state.imagenum); // of times you repeat that loop to make the stream.close(); application more CPU- // bound or more IO-bound. public static int processimagerepeats = 20; // Now write out the image. AsyncCallback readimagecallback = new ("In ReadInImageCallback, got the wrong number of " + AsyncCallback(ReadInImageCallback); Mostly queued, suspended and for (int i = 0; i < numimages; i++) { executed ImageStateObject state in = the new ImageStateObject(); thread pool state.pixels = new byte[numpixels]; state.imagenum = i; // Using asynchronous I/O here appears not to be best practice. // Very large items are read only once, so you can make the // Threads must decrement NumImagesToFinish, // It and ends protect up swamping the threadpool, because the threadpool // buffer on the FileStream very small to save memory. // their access to it through a mutex. // threads are blocked on I/O requests that were just queued tofilestream fs = new FileStream(ImageBaseName + i + ".tmp", public static int NumImagesToFinish = numimages; // the threadpool. FileMode.Open, FileAccess.Read, FileShare.Read, 1, true); public static Object[] NumImagesMutex = new FileStream Object[0]; fs = new FileStream(ImageBaseName + state.imagenum + state.fs = fs; // WaitObject is signalled when all image processing ".done", is FileMode.Create, done. FileAccess.Write, FileShare.None, fs.beginread(state.pixels, 0, numpixels, readimagecallback, public static Object[] WaitObject = new Object[0]; 4096, false); state); public class ImageStateObject fs.write(state.pixels, 0, numpixels); } { fs.close(); public byte[] pixels; // Determine whether all images are done being processed. public int imagenum; // This application model uses too much memory. // If not, block until all are finished. } public static void ReadInImageCallback(IAsyncResult asyncresult) { public static void ProcessImagesInBulk() ImageStateObject state = (ImageStateObject)asyncResult.AsyncState; { Console.WriteLine("Processing images... "); tasks long t0 = Environment.TickCount; NumImagesToFinish = numimages; public let ProcessImageAsync FileStream fs; () = // Releasing memory as soon as possible is a good idea, async { let instream = File.OpenRead(sprintf // especially global "Image%d.tmp" state. i) let! pixels = instream.readasync(numpixels) state.pixels = null; let pixels' = TransformImage(pixels,i) fs = null; let outstream = File.OpenWrite(sprintf // Record that an "Image%d.done" image is finished i) now. do! outstream.writeasync(pixels') lock (NumImagesMutex) do Console.WriteLine "done!" { } NumImagesToFinish--; let ProcessImagesAsyncWorkflow() = if (NumImagesToFinish == 0) Async.Run (Async.Parallel { [ for i in 1.. numimages -> Monitor.Enter(WaitObject); ProcessImageAsync i ]) Monitor.Pulse(WaitObject); Monitor.Exit(WaitObject); } } } } Create 10, 000s of asynchronous Exceptions can be handled } bool mustblock = false; lock properly (NumImagesMutex) { if (NumImagesToFinish > 0) mustblock = true; } if (mustblock) { automatically Console.WriteLine("All worker threads are queued. " + " Blocking until they complete. numleft: {0}", NumImagesToFinish); Monitor.Enter(WaitObject); Monitor.Wait(WaitObject); Monitor.Exit(WaitObject); } long properly t1 = Environment.TickCount; on failure Console.WriteLine("Total time processing images: {0}ms", (t1 - t0)); Cancellation checks inserted Resources can be disposed CPU threads are not blocked

22 Don Syme

23 Uses Computational LOP to make writing continuation-passing programs simpler and compositional Execution request Async<T> Similar to techniques used in Haskell Success continuation Exception continuation Cancellation continuation A wrapper over the.net Thread Pool and.net synchronization primitives

24 async { let! image = ReadAsync "cat.jpg" let image2 = f image do! writeasync image2 "dog.jpg" do printfn "done!" return image2 } Asynchronous "nonblocking" action Continuation/ Event callback You're actually writing this (approximately): async.delay(fun () -> async.bind(readasync "cat.jpg", (fun image -> async.bind(async.return(f image),(fun image2 async.bind(writeasync "dog.jpg",(fun () -> async.bind(async.return(printfn "done!"),(fun () -> async.return())))))))))

25 Don Syme

26 A custom programming language designed to solve a specific set of problems Examples Excel Windows Shell Regular Expressions HTML

27 A style where you apply the ideas of a DSL in a general purpose programming language Bridges the gap between a separate, domainspecific language and the code you write Ability to process problems described in a DSL

28 XML a concrete language representation A parser tree or object model is an abstract language representation Asynchronous workflows are a integrated language representation

29 The language is in the data XML, CSV, Text, Strings, JSON Parse Trees The language is in the code Almost- Implicit Parallelism Queries Exception Handling Workflows

30 XML Libraries RegExp Libraries Lex/Yacc... Discriminated Unions Pattern Matching F# Computation Expressions Expression Trees

31

32 F# has capabilities which enable LOP Representing other languages in F# Extracting other languages into F# Allowing F# to process in other languages/domains LOP makes code that is cleaner and easier to understand

33 Get F# Includes add-in for VS2005 and VS2008 Books Expert F# Don Syme, Adam Granicz, and Antonio Cisternino Foundations of F# Robert Pickering Websites

34 Don Syme

35 open Microsoft.FSharp.Control.Mailboxes let counter = MailboxProcessor.Create(fun inbox -> /// Loop, receiving messages let rec loop(n) = async { do printfn "n = %d" n let! msg = inbox.receive() return! loop(n+msg) } /// Enter the loop loop(0))

36

37 Visit Don Syme

Why is Microsoft investing in Functional Programming?

Why is Microsoft investing in Functional Programming? Why is Microsoft investing in Functional Programming? Don Syme With thanks to Leon Bambrick, Chris Smith and the puppies All opinions are those of the author and not necessarily those of Microsoft Simplicity

More information

Don Syme, Principal Researcher Microsoft Research, Cambridge

Don Syme, Principal Researcher Microsoft Research, Cambridge F# Succinct, Expressive, Functional Don Syme, Principal Researcher Microsoft Research, Cambridge Topics What is F# about? Some Simple F# Programming A Taste of Parallel/Reactive with F# What is F# about?

More information

High Performance and Productivity Computing with Windows HPC George Yan. Group Manager Windows HPC Microsoft China

High Performance and Productivity Computing with Windows HPC George Yan. Group Manager Windows HPC Microsoft China High Performance and Productivity Computing with Windows HPC George Yan Group Manager Windows HPC Microsoft China HPC at Microsoft 1997 NCSA deploys first Windows clusters on NT4 2000 Windows Server 2000

More information

F# Succinct, Expressive, Efficient Functional Programming for.net

F# Succinct, Expressive, Efficient Functional Programming for.net F# Succinct, Expressive, Efficient Functional Programming for.net The F# Team Microsoft Developer Division, Redmond Microsoft Research, Cambridge Topics What is F# about? Some Simple F# Programming A Taste

More information

F# Succinct, Expressive, Efficient. The F# Team Microsoft Developer Division, Redmond Microsoft Research, Cambridge

F# Succinct, Expressive, Efficient. The F# Team Microsoft Developer Division, Redmond Microsoft Research, Cambridge F# Succinct, Expressive, Efficient Functional Programming for.net The F# Team Microsoft Developer Division, Redmond Microsoft Research, Cambridge Topics What is F# about? Some Simple F# Programming A Taste

More information

Expert F# Don Syme, Adam Granicz, and Antonio Cisternino

Expert F# Don Syme, Adam Granicz, and Antonio Cisternino Expert F# Don Syme, Adam Granicz, and Antonio Cisternino Expert F# Copyright 2007 by Don Syme, Adam Granicz, and Antonio Cisternino All rights reserved. No part of this work may be reproduced or transmitted

More information

Asynchronous Computations

Asynchronous Computations CITS 3242 Programming Paradigms Part III: Concurrent Programming Topic 14: Asynchronous Computations Asynchronous computations are lightweight software threads supported by the runtime that are more efficient

More information

Asynchronous Programming Model (APM) 1 Calling Asynchronous Methods Using IAsyncResult 4 Blocking Application Execution by Ending an Async Operation

Asynchronous Programming Model (APM) 1 Calling Asynchronous Methods Using IAsyncResult 4 Blocking Application Execution by Ending an Async Operation Asynchronous Programming Model (APM) 1 Calling Asynchronous Methods Using IAsyncResult 4 Blocking Application Execution by Ending an Async Operation 5 Blocking Application Execution Using an AsyncWaitHandle

More information

C# Asynchronous Programming Model

C# Asynchronous Programming Model Spring 2014 C# Asynchronous Programming Model A PRACTICAL GUIDE BY CHRIS TEDFORD TABLE OF CONTENTS Introduction... 2 Background Information... 2 Basic Example... 3 Specifications and Usage... 4 BeginInvoke()...

More information

Asynchronous Message Passing

Asynchronous Message Passing CITS 3242 Programming Paradigms Part III: Concurrent Programming Topic 15: Asynchronous Message Passing Message passing is an important alternative to shared memory concurrency. It avoids the issues related

More information

Learning F# and the Functional Point of View. Robert Pickering, LexiFi

Learning F# and the Functional Point of View. Robert Pickering, LexiFi Learning F# and the Functional Point of View Robert Pickering, LexiFi http://strangelights.com Session Objectives Why was F# created? Why learn F#? A taste of the F# language Especially the functional

More information

Reactive programming, WinForms,.NET. Björn Dagerman

Reactive programming, WinForms,.NET. Björn Dagerman Reactive programming, WinForms,.NET Björn Dagerman Motivation - Troublesome for many students previous years - Most student solutions we see are imperative - Useful techniques when working with GUI s,

More information

Threads are lightweight processes responsible for multitasking within a single application.

Threads are lightweight processes responsible for multitasking within a single application. Threads Threads are lightweight processes responsible for multitasking within a single application. The class Thread represents an object-oriented wrapper around a given path of execution. The class Thread

More information

Simplifying Asynchronous Programming with Microsoft Visual Studio Async CTP

Simplifying Asynchronous Programming with Microsoft Visual Studio Async CTP Simplifying Asynchronous Programming with Microsoft Visual Studio Async CTP Nelson Morais Universidade Lusófona de Humanidades e Tecnologias Campo Grande, 376 1749-021 Lisboa (Portugal) +351 91 732 46

More information

F# Succinct, Expressive, Functional. The F# Team Microsoft Developer Division Microsoft Research

F# Succinct, Expressive, Functional. The F# Team Microsoft Developer Division Microsoft Research F# Succinct, Expressive, Functional The F# Team Microsoft Developer Division Microsoft Research Topics What is F# about? Some Simple F# Programming A Taste of Parallel/Reactive with F# What is F# about?

More information

Concurrent Programming

Concurrent Programming Concurrent Programming Adam Przybyłek, 2016 przybylek.wzr.pl This work is licensed under a Creative Commons Attribution 4.0 International License. Task Parallel Library (TPL) scales the degree of concurrency

More information

Functional Programming and Parallel Computing

Functional Programming and Parallel Computing Functional Programming and Parallel Computing Björn Lisper School of Innovation, Design, and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ Functional Programming and

More information

Rx is a library for composing asynchronous and event-based programs using observable collections.

Rx is a library for composing asynchronous and event-based programs using observable collections. bartde@microsoft.com Slides license: Creative Commons Attribution Non-Commercial Share Alike See http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode Too hard today (f g)(x) = f(g(x)) Rx is a library

More information

Multithreading and Interactive Programs

Multithreading and Interactive Programs Multithreading and Interactive Programs CS160: User Interfaces John Canny. This time Multithreading for interactivity need and risks Some design patterns for multithreaded programs Debugging multithreaded

More information

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com 70-483 MCSA Universal Windows Platform A Success Guide to Prepare- Programming in C# edusum.com Table of Contents Introduction to 70-483 Exam on Programming in C#... 2 Microsoft 70-483 Certification Details:...

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

JS Event Loop, Promises, Async Await etc. Slava Kim

JS Event Loop, Promises, Async Await etc. Slava Kim JS Event Loop, Promises, Async Await etc Slava Kim Synchronous Happens consecutively, one after another Asynchronous Happens later at some point in time Parallelism vs Concurrency What are those????

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

More information

CITS 3242 Programming Paradigms Part II. Topic 10: Imperative Programming

CITS 3242 Programming Paradigms Part II. Topic 10: Imperative Programming CITS 3242 Programming Paradigms Part II Topic 10: Imperative Programming This topic covers the background and motivations for imperative programming, as well as the imperative constructs in F# - reference

More information

The Future of Parallel Programming in the.net Framework. Igor Ostrovsky Software Engineer Microsoft Corporation

The Future of Parallel Programming in the.net Framework. Igor Ostrovsky Software Engineer Microsoft Corporation The Future of Parallel Programming in the.net Framework Igor Ostrovsky Software Engineer Microsoft Corporation DISCLAIMER This is a talk about the near future All content is subject to change. The technology

More information

Using Scala for building DSL s

Using Scala for building DSL s Using Scala for building DSL s Abhijit Sharma Innovation Lab, BMC Software 1 What is a DSL? Domain Specific Language Appropriate abstraction level for domain - uses precise concepts and semantics of domain

More information

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

EEE-448 COMPUTER NETWORKS (Programming) Week -6 C# & IP Programming. The StringBuilder Class. StringBuilder Classes. StringBuilder with Append

EEE-448 COMPUTER NETWORKS (Programming) Week -6 C# & IP Programming. The StringBuilder Class. StringBuilder Classes. StringBuilder with Append EEE-448 COMPUTER NETWORKS (Programming) Week -6 C# & IP Programming Turgay IBRIKCI, PhD EEE448 Computer Networks Spring 2011 EEE448 Computer Networks Spring 2011 The StringBuilder Class The StringBuilder

More information

Sri Lanka Institute of Information Technology System Programming and Design II Year 3 Tutorial 06

Sri Lanka Institute of Information Technology System Programming and Design II Year 3 Tutorial 06 Sri Lanka Institute of Information Technology System Programming and Design II Year 3 Tutorial 06 1. What is an asynchronous call? How does it differ from a synchronous call? In synchronous call, the caller

More information

C# Threading. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

C# Threading. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh C# Threading Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 1 2018/19 0 Based on: "An Introduction to programming with

More information

Software Architecture

Software Architecture Software Architecture Lecture 5 Call-Return Systems Rob Pettit George Mason University last class data flow data flow styles batch sequential pipe & filter process control! process control! looping structure

More information

AC: COMPOSABLE ASYNCHRONOUS IO FOR NATIVE LANGUAGES. Tim Harris, Martín Abadi, Rebecca Isaacs & Ross McIlroy

AC: COMPOSABLE ASYNCHRONOUS IO FOR NATIVE LANGUAGES. Tim Harris, Martín Abadi, Rebecca Isaacs & Ross McIlroy AC: COMPOSABLE ASYNCHRONOUS IO FOR NATIVE LANGUAGES Tim Harris, Martín Abadi, Rebecca Isaacs & Ross McIlroy Synchronous IO in the Windows API Read the contents of h, and compute a result BOOL ProcessFile(HANDLE

More information

DOT NET Syllabus (6 Months)

DOT NET Syllabus (6 Months) DOT NET Syllabus (6 Months) THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In- Time Compilation and CLS Disassembling.Net Application to IL

More information

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Microsoft. Microsoft Visual C# Step by Step. John Sharp Microsoft Microsoft Visual C#- 2010 Step by Step John Sharp Table of Contents Acknowledgments Introduction xvii xix Part I Introducing Microsoft Visual C# and Microsoft Visual Studio 2010 1 Welcome to

More information

MCS-378 Intraterm Exam 1 Serial #:

MCS-378 Intraterm Exam 1 Serial #: MCS-378 Intraterm Exam 1 Serial #: This exam is closed-book and mostly closed-notes. You may, however, use a single 8 1/2 by 11 sheet of paper with hand-written notes for reference. (Both sides of the

More information

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Fall 2017 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory All

More information

INTERFACING REAL-TIME AUDIO AND FILE I/O

INTERFACING REAL-TIME AUDIO AND FILE I/O INTERFACING REAL-TIME AUDIO AND FILE I/O Ross Bencina portaudio.com rossbencina.com rossb@audiomulch.com @RossBencina Example source code: https://github.com/rossbencina/realtimefilestreaming Q: How to

More information

Swift 5, ABI Stability and

Swift 5, ABI Stability and Swift 5, ABI Stability and Concurrency @phillfarrugia Important Documents Concurrency Manifesto by Chris Lattner https: /gist.github.com/lattner/ 31ed37682ef1576b16bca1432ea9f782 Kicking off Concurrency

More information

Five Reasons to Move from C# to F#

Five Reasons to Move from C# to F# Five Reasons to Move from C# to F# JORGE FIORANELLI LEAD CONSULTANT @ JORGEFIORANELLI Who am I? Readify Lead Consultant - Sydney, Australia F# Sydney User Group (fsharpsydney.com) F# Workshop (fsharpworkshop.com)

More information

Microsoft Visual C# Step by Step. John Sharp

Microsoft Visual C# Step by Step. John Sharp Microsoft Visual C# 2013 Step by Step John Sharp Introduction xix PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2013 Chapter 1 Welcome to C# 3 Beginning programming with the Visual

More information

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017 CS 471 Operating Systems Yue Cheng George Mason University Fall 2017 Outline o Process concept o Process creation o Process states and scheduling o Preemption and context switch o Inter-process communication

More information

MF#K - Introduction to F# GroupM Mødegruppe for Ƒunktionelle Københavnere (MF#K)

MF#K - Introduction to F# GroupM Mødegruppe for Ƒunktionelle Københavnere (MF#K) MF#K - Introduction to F# meeting @ GroupM 2015-07-08 Mødegruppe for Ƒunktionelle Københavnere (MF#K) Overview About me Matching of expectations Agenda 15:30 > Short introduction to F# (sales pitch) 15:50

More information

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza

More information

Operating systems and concurrency (B08)

Operating systems and concurrency (B08) Operating systems and concurrency (B08) David Kendall Northumbria University David Kendall (Northumbria University) Operating systems and concurrency (B08) 1 / 20 Introduction Semaphores provide an unstructured

More information

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

Exercise Session Week 8

Exercise Session Week 8 Chair of Software Engineering Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 8 Quiz 1: What is printed? (Java) class MyTask implements Runnable { public void

More information

Compose Chaos. Part 1: RAII Applied to Concurrency <image of chaos in a lego piece shape>

Compose Chaos. Part 1: RAII Applied to Concurrency <image of chaos in a lego piece shape> Compose Chaos Part 1: RAII Applied to Concurrency 1 A. Joël Lamotte - Experience: Games, Tools, Embedded, Mobile, Web... - C++, Python, C#, JavaScript, Java, ActionScript...

More information

Transactum Business Process Manager with High-Performance Elastic Scaling. November 2011 Ivan Klianev

Transactum Business Process Manager with High-Performance Elastic Scaling. November 2011 Ivan Klianev Transactum Business Process Manager with High-Performance Elastic Scaling November 2011 Ivan Klianev Transactum BPM serves three primary objectives: To make it possible for developers unfamiliar with distributed

More information

CS 160: Interactive Programming

CS 160: Interactive Programming CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2

More information

Reminder from last time

Reminder from last time Concurrent systems Lecture 3: CCR, monitors, and concurrency in practice DrRobert N. M. Watson 1 Reminder from last time Implementing mutual exclusion: hardware support for atomicity and inter-processor

More information

A Pattern for Storing Structured Data in AutoCAD Entities

A Pattern for Storing Structured Data in AutoCAD Entities A Pattern for Storing Structured Data in AutoCAD Entities Jeffery Geer RCM Technologies CP401-2 Xrecords provide storage of information in AutoCAD entities, but defining that structure can be a cumbersome

More information

Piqi-RPC. Exposing Erlang services via JSON, XML and Google Protocol Buffers over HTTP. Friday, March 25, 2011

Piqi-RPC. Exposing Erlang services via JSON, XML and Google Protocol Buffers over HTTP. Friday, March 25, 2011 Piqi-RPC Exposing Erlang services via JSON, XML and Google Protocol Buffers over HTTP 1 Anton Lavrik http://piqi.org http://www.alertlogic.com 2 Overview Call Erlang functions using HTTP POST : Server

More information

Programming in Scala Second Edition

Programming in Scala Second Edition Programming in Scala Second Edition Martin Odersky, Lex Spoon, Bill Venners artima ARTIMA PRESS WALNUT CREEK, CALIFORNIA Contents Contents List of Figures List of Tables List of Listings Foreword Foreword

More information

Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo Programming C# 5.0 Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo Preface xvii 1. Introducing C# 1 Why C#? 1 Why Not C#? 3 C#'s Defining Features 5 Managed Code and the CLR 7

More information

Compositional C++ Page 1 of 17

Compositional C++ Page 1 of 17 Compositional C++ Page 1 of 17 Compositional C++ is a small set of extensions to C++ for parallel programming. OVERVIEW OF C++ With a few exceptions, C++ is a pure extension of ANSI C. Its features: Strong

More information

The Mercury project. Zoltan Somogyi

The Mercury project. Zoltan Somogyi The Mercury project Zoltan Somogyi The University of Melbourne Linux Users Victoria 7 June 2011 Zoltan Somogyi (Linux Users Victoria) The Mercury project June 15, 2011 1 / 23 Introduction Mercury: objectives

More information

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Spring 2018 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory

More information

Vulkan: Scaling to Multiple Threads. Kevin sun Lead Developer Support Engineer, APAC PowerVR Graphics

Vulkan: Scaling to Multiple Threads. Kevin sun Lead Developer Support Engineer, APAC PowerVR Graphics Vulkan: Scaling to Multiple Threads Kevin sun Lead Developer Support Engineer, APAC PowerVR Graphics www.imgtec.com Introduction Who am I? Kevin Sun Working at Imagination Technologies Take responsibility

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018 SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T 2. 3. 8 A N D 2. 3. 1 0 S P R I N G 2018 INTER-PROCESS COMMUNICATION 1. How a process pass information to another process

More information

Exercise Session Week 8

Exercise Session Week 8 Chair of Software Engineering Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 8 Java 8 release date Was early September 2013 Currently moved to March 2014 http://openjdk.java.net/projects/jdk8/milestones

More information

Virtual Machine Design

Virtual Machine Design Virtual Machine Design Lecture 4: Multithreading and Synchronization Antero Taivalsaari September 2003 Session #2026: J2MEPlatform, Connected Limited Device Configuration (CLDC) Lecture Goals Give an overview

More information

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop. 2016 Spis treści Preface xi 1. Introducing C# and the.net Framework 1 Object Orientation 1 Type Safety 2 Memory Management

More information

Reactive design patterns for microservices on multicore

Reactive design patterns for microservices on multicore Reactive Software with elegance Reactive design patterns for microservices on multicore Reactive summit - 22/10/18 charly.bechara@tredzone.com Outline Microservices on multicore Reactive Multicore Patterns

More information

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

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2. Learning Outcomes Concurrency and Synchronisation Understand concurrency is an issue in operating systems and multithreaded applications Know the concept of a critical region. Understand how mutual exclusion

More information

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing

More information

List of Code Samples. xiii

List of Code Samples. xiii xiii List of Code Samples Sample 1-1 Driving the APB pins 16 Sample 1-2 A task to drive the APB pins 17 Sample 1-3 Low-level Verilog test 17 Sample 1-4 Basic transactor code 21 Sample 2-1 Using the logic

More information

What should we do with this freedom?

What should we do with this freedom? Rotor (and the CLR), re-enable language experimentation. A pre-approved multi-language environment. With a flexible attitude towards further innovation. Open to the wider community. What should we do with

More information

Processes and Threads

Processes and Threads TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Processes and Threads [SGG7] Chapters 3 and 4 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

More information

Java SE7 Fundamentals

Java SE7 Fundamentals Java SE7 Fundamentals Introducing the Java Technology Relating Java with other languages Showing how to download, install, and configure the Java environment on a Windows system. Describing the various

More information

Threads and Locks, Part 2. CSCI 5828: Foundations of Software Engineering Lecture 08 09/18/2014

Threads and Locks, Part 2. CSCI 5828: Foundations of Software Engineering Lecture 08 09/18/2014 Threads and Locks, Part 2 CSCI 5828: Foundations of Software Engineering Lecture 08 09/18/2014 1 Goals Cover the material presented in Chapter 2 of our concurrency textbook In particular, selected material

More information

Apache Thrift Introduction & Tutorial

Apache Thrift Introduction & Tutorial Apache Thrift Introduction & Tutorial Marlon Pierce, Suresh Marru Q & A TIOBE Index Programming Language polyglotism Modern distributed applications are rarely composed of modules written in a single language.

More information

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar Design Patterns MSc in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie)! Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

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

Concurrency and Synchronisation

Concurrency and Synchronisation Concurrency and Synchronisation 1 Learning Outcomes Understand concurrency is an issue in operating systems and multithreaded applications Know the concept of a critical region. Understand how mutual exclusion

More information

Parallel Processing: Performance Limits & Synchronization

Parallel Processing: Performance Limits & Synchronization Parallel Processing: Performance Limits & Synchronization Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. May 8, 2018 L22-1 Administrivia Quiz 3: Thursday 7:30-9:30pm, room 50-340

More information

CSE 451 Midterm 1. Name:

CSE 451 Midterm 1. Name: CSE 451 Midterm 1 Name: 1. [2 points] Imagine that a new CPU were built that contained multiple, complete sets of registers each set contains a PC plus all the other registers available to user programs.

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

More information

Actors in the Small. Making Actors more Useful. Bill La

Actors in the Small. Making Actors more Useful. Bill La Actors in the Small Making Actors more Useful Bill La Forge laforge49@gmail.com @laforge49 Actors in the Small I. Introduction II. Making Actors Fast III.Making Actors Easier to Program IV. Tutorial I.

More information

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: concurrency Outline Java threads thread implementation sleep, interrupt, and join threads that return values Thread synchronization

More information

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++ Crash Course in Java Netprog: Java Intro 1 Why Java? Network Programming in Java is very different than in C/C++ much more language support error handling no pointers! (garbage collection) Threads are

More information

Spring MVC 4.x Spring 5 Web Reactive

Spring MVC 4.x Spring 5 Web Reactive Part 1 Spring MVC 4.x Spring 5 Web Reactive Rossen Stoyanchev @rstoya05 Spring MVC 4.3 Reactive programming for Java devs Spring 5 Web Reactive Shortcut Annotations @RequestMapping @GetMapping @PostMapping

More information

Kotlin/Native concurrency model. nikolay

Kotlin/Native concurrency model. nikolay Kotlin/Native concurrency model nikolay igotti@jetbrains What do we want from concurrency? Do many things concurrently Easily offload tasks Get notified once task a task is done Share state safely Mutate

More information

Last Class: Synchronization

Last Class: Synchronization Last Class: Synchronization Synchronization primitives are required to ensure that only one thread executes in a critical section at a time. Concurrent programs Low-level atomic operations (hardware) load/store

More information

CSE 451: Operating Systems Winter I/O System. Gary Kimura

CSE 451: Operating Systems Winter I/O System. Gary Kimura CSE 451: Operating Systems Winter 2012 I/O System Gary Kimura What s Ahead Principles of I/O Hardware Structuring of I/O Software Layers of an I/O System Operation of an I/O System 2 Hardware Environment

More information

Lecture 21: Concurrency in Other Environments (Part 2)

Lecture 21: Concurrency in Other Environments (Part 2) COMP 150-CCP Concurrent Programming Lecture 21: Concurrency in Other Environments (Part 2) Dr. Richard S. Hall rickhall@cs.tufts.edu Clement Escoffier clement.escoffier@gmail.com Concurrent programming

More information

OCaml Language Choices CMSC 330: Organization of Programming Languages

OCaml Language Choices CMSC 330: Organization of Programming Languages OCaml Language Choices CMSC 330: Organization of Programming Languages! Implicit or explicit declarations?! Explicit variables must be introduced with let before use! But you don t need to specify types

More information

Synchronization SPL/2010 SPL/20 1

Synchronization SPL/2010 SPL/20 1 Synchronization 1 Overview synchronization mechanisms in modern RTEs concurrency issues places where synchronization is needed structural ways (design patterns) for exclusive access 2 Overview synchronization

More information

CS 31: Intro to Systems Misc. Threading. Kevin Webb Swarthmore College December 6, 2018

CS 31: Intro to Systems Misc. Threading. Kevin Webb Swarthmore College December 6, 2018 CS 31: Intro to Systems Misc. Threading Kevin Webb Swarthmore College December 6, 2018 Classic thread patterns Agenda Pthreads primitives and examples of other forms of synchronization: Condition variables

More information

Investigating F# as a development tool for distributed multi-agent systems

Investigating F# as a development tool for distributed multi-agent systems PROCEEDINGS OF THE WORKSHOP ON APPLICATIONS OF SOFTWARE AGENTS ISBN 978-86-7031-188-6, pp. 32-36, 2011 Investigating F# as a development tool for distributed multi-agent systems Extended abstract Alex

More information

Implementation of F# language support in JetBrains Rider IDE

Implementation of F# language support in JetBrains Rider IDE SAINT-PETERSBURG STATE UNIVERSITY Software Engineering Evgeniy Auduchinok Implementation of F# language support in JetBrains Rider IDE Graduation Thesis Scientific supervisor: Senior lecturer Iakov Kirilenko

More information

COMP 3430 Robert Guderian

COMP 3430 Robert Guderian Operating Systems COMP 3430 Robert Guderian file:///users/robg/dropbox/teaching/3430-2018/slides/06_concurrency/index.html?print-pdf#/ 1/76 1 Concurrency file:///users/robg/dropbox/teaching/3430-2018/slides/06_concurrency/index.html?print-pdf#/

More information

Today: Distributed Middleware. Middleware

Today: Distributed Middleware. Middleware Today: Distributed Middleware Middleware concepts Case study: CORBA Lecture 24, page 1 Middleware Software layer between application and the OS Provides useful services to the application Abstracts out

More information

Atomicity CS 2110 Fall 2017

Atomicity CS 2110 Fall 2017 Atomicity CS 2110 Fall 2017 Parallel Programming Thus Far Parallel programs can be faster and more efficient Problem: race conditions Solution: synchronization Are there more efficient ways to ensure the

More information

Process Synchronization(2)

Process Synchronization(2) EECS 3221.3 Operating System Fundamentals No.6 Process Synchronization(2) Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University Semaphores Problems with the software solutions.

More information

Programming Safe Agents in Blueprint. Alex Muscar University of Craiova

Programming Safe Agents in Blueprint. Alex Muscar University of Craiova Programming Safe Agents in Blueprint Alex Muscar University of Craiova Programmers are craftsmen, and, as such, they are only as productive as theirs tools allow them to be Introduction Agent Oriented

More information

Concurrency Abstractions in C#

Concurrency Abstractions in C# 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

More information

Programming Languages

Programming Languages TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Concurrency: Atomic Executions, Locks and Monitors Dr. Michael Petter Winter term 2016 Atomic Executions, Locks and Monitors

More information

Part I: Communication and Networking

Part I: Communication and Networking Review what we learned Part I: Communication and Networking Communication and Networking: Week 5-6, Lectures 2-7 Lecture 1 OSI vs TCP/IP model OSI model Protocols TCP/IP model Application FTP SMTP HTTP

More information