 Parallel Programming in C# Pro.Net Programming in C#, Adam Freeman.

Slides:



Advertisements
Similar presentations
Generalized Requests. The current definition They are defined in MPI 2 under the hood of the chapter 8 (External Interfaces) Page 166 line 16 The objective.
Advertisements

Practical Session 6 Multitasking vs. multithreading Threads Concurrency vs. Parallelism Java Threads Thread confinement Object/Class Immutability.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 10: Advanced Object-Oriented Mechanisms (based on.
Deadlocks, Message Passing Brief refresh from last week Tore Larsen Oct
Lightweight Concurrent Tasks Lecture 1.d 6/16/2010 Practical Parallel and Concurrent Programming DRAFT: comments to 1.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Async Programming WITH ASYNC TASK
Designing a thread-safe class  Store all states in public static fields  Verifying thread safety is hard  Modifications to the program hard  Design.
Chapter 5 Processes and Threads Copyright © 2008.
Distributed systems Programming with threads. Reviews on OS concepts Each process occupies a single address space.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Concurrency…leading up to writing a web crawler. Web crawlers.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L20 (Chapter 24) Multithreading.
PARALLEL PROGRAMMING ABSTRACTIONS 6/16/2010 Parallel Programming Abstractions 1.
Parallel Programming in.NET Kevin Luty.  History of Parallelism  Benefits of Parallel Programming and Designs  What to Consider  Defining Types of.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Threads in Java a tutorial introduction (revision 7) Christian Ratliff Senior Technology Architect Core Libraries.
RISICO on the GRID architecture First implementation Mirko D'Andrea, Stefano Dal Pra.
Grid Resource Allocation and Management (GRAM) Execution management Execution management –Deployment, scheduling and monitoring Community Scheduler Framework.
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Task Parallel Library (TPL)
Operating Systems Chapter 2
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Proactor Pattern Venkita Subramonian & Christopher Gill
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
ADVANCED WEB SERVICES. Three Advanced Web Service Techniques SOAP Extensions Asynchronous calls Custom wire formatting SOAP Extensions Asynchronous calls.
Ada How was Ada conceived. The language, not the lady.
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Chapter 4 – Threads (Pgs 153 – 174). Threads  A "Basic Unit of CPU Utilization"  A technique that assists in performing parallel computation by setting.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Asynchronous Programming Writing Asynchronous Code in C# SoftUni Team Technical Trainers Software University
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Module 8 Enhancing User Interface Responsiveness.
Plinq Presentation Steen L. Knudsen
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
TAP into async programming
Parallel Debugging in VS2010 Two new debugger toolwindows Support both native and managed “Parallel Stacks” Call stacks of all threads or tasks “Parallel.
Образец заголовка Образец текста –Второй уровень Третий уровень –Четвертый уровень »Пятый уровень Тема: Task Parallel Library Крыжановский Анатолий.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
1.NETDelegates & eventsNOEA / PQC 2007 Delegates & events Observer pattern Delegates –Semantics –Cil – code –Usage Events Asynchronious delegates.
Windows Workflow Foundation Guy Burstein Senior Consultant Advantech – Microsoft Division
Business Process Execution Language (BPEL) Pınar Tekin.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Chapter 4: Threads.
Reactive Android Development
TechEd /6/2018 6:15 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Advanced C++ Programming
Async or Parallel? No they aren’t the same thing!
Task Parallel Library: Design Principles and Best Practices
Using local variable without initialization is an error.
Functional Programming with Java
More! Multi-threaded Development
Staying Afloat in the .NET Async Ocean
دانشیار دانشکده دندانپزشکی دانشگاه علوم پزشکی شهید صدوقی یزد
Shared Memory Programming
Thread Implementation Issues
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Threads Chapter 4.
Web programming and advanced development techniques
Multithread Programming
Class 4: Repetition Pretest Posttest Counting Flowchart these!
CS561 Computer Architecture Hye Yeon Kim
Lecture 20 Parallel Programming CSE /8/2019.
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

 Parallel Programming in C# Pro.Net Programming in C#, Adam Freeman

Parallel C#  Task Parallel Library (TPL)  TPL tasks vs. Threads  Benefits & Pitfalls of Parallel Programming  Overhead  Coordinating fata  Scaling Applications

Task Programming  Creating and starting tasks  Task.Factory.StartNew()  Task.Start()  Setting task state  System.Action  Passing parameters to tasks  Getting a result  Task.Result

Task Programming  Task creation options  PreferFairness  LongRunning  AttachedToParent  Identifying tasks  Task.CurrentId

Cancelling tasks  Simpler, more consistent and reduced risk task creation  Steps:  Create a new instance of CancellationTokenSource  Call CancellationTokenSource.Token property to get a Cancellationtoken  Create a new task with this token  Call Start() method of the task to start this task  Call CancellationTokenSource.Cancel() method to cancel the task

Cancelling tasks  Who is responsible of cancelling a task?  Cancellation procedure in a task  Polling  Using a delegate  Cancelling with a wait handle  Cancelling several tasks  Composite cancellation tokens  Determine task is cancelled

Waiting time to pass  Sleeping  Using cancellation token wait handle  Using classic Thread.Sleep()  Using Thread.SpinWait()

Waiting for tasks  What if there is no Task.Result?  Waiting for single task: Wait(), Wait(CancellationToken), Wait(Int32), Wait(TimeSpan), Wait(Int32, CancellationToken)  Wait for several tasks: WaitAll(), WaitAny()

Handling exceptions  Basic exceptions: AggregateException  Iterative handler: AggregateException.Handle()  Reading task properties:  IsCompleted  IsFaulted  IsCancelled  Exception

Getting status of a task  Created  WaitingForActivation || WaitingToRun  Running  WaitingForChildrenToComplete  RanToCompletion  Canceled  Faulted

Executing tasks lazily  Execute task when needed.  Anonymous functions  Lazy

Common problems  Task dependency deadlock  Local variable evaluation  Excessive spinning