Asynchronous Programming CS Programming Languages for Web Applications

Slides:



Advertisements
Similar presentations
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Advertisements

Structured Thread Models Kahn Process Networks, CSP, Go 1Dennis Kafura – CS5204 – Operating Systems.
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
CS533 Concepts of Operating Systems Jonathan Walpole.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Node.js - What is Node.js? -
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
1 Web Based Programming Section 8 James King 12 August 2003.
Concurrent Programming and Threads Threads Blocking a User Interface.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Code Development for High Performance Servers Topics Multithreaded Servers Event Driven Servers Example - Game Server code (Quake) A parallelization exercise.
Multithreading The objectives of this chapter are: To understand the purpose of multithreading To describe Java's multithreading mechanism.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
CSE 434: Computer Networks Project Single vs. Per Connection vs. Pooling Threading Techniques Dominic Hilsbos, Dorothy Johnson, Chris Volpe, Andy Wong,
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
OPERATING SYSTEM CONCEPT AND PRACTISE
Processes and threads.
Advanced Operating Systems CIS 720
Reactive Android Development
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Practice Chapter Four.
Processes and Threads Processes and their scheduling
CS240: Advanced Programming Concepts
CS399 New Beginnings Jonathan Walpole.
Chapter 4: Threads.
Chapter 4: Multithreaded Programming
Event Driven Programming Dick Steflik
William Stallings Computer Organization and Architecture
CS533 Concepts of Operating Systems
CS 3305 System Calls Lecture 7.
Intro to Processes CSSE 332 Operating Systems
Reactive Android Development
Client-Server Interaction
Chapter 4: Threads.
Event Driven Programming
Process management Information maintained by OS for process management
Chapter 4: Threads.
12 Asynchronous Programming
Android Programming Lecture 8
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Operating Systems.
Welcome to SCRATCH.
Android Topics Asynchronous Callsbacks
Threaded Programming in Python
EE 472 – Embedded Systems Dr. Shwetak Patel.
CS5220 Advanced Topics in Web Programming More Node.js
Threads vs. Processes Hank Levy 1.
State Handling CS 4640 Programming Languages for Web Applications
Processes and Process Table
[Based in part on SWE 432 and SWE 632 materials by Jeff Offutt, GMU]
Chapter 4: Threads.
CS703 – Advanced Operating Systems
EECE.4810/EECE.5730 Operating Systems
CS5220 Advanced Topics in Web Programming More Node.js
Software Engineering and Architecture
State Handling CS 4640 Programming Languages for Web Applications
[Based in part on SWE 432 and SWE 632 materials by Jeff Offutt, GMU]
JavaScript CS 4640 Programming Languages for Web Applications
CS533 Concepts of Operating Systems Class 4
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Asynchronous Programming CS 4640 Programming Languages for Web Applications [Joshua Bloch, “Effective Java” Robert W. Sebesta, “Programming the World Wide Web Based in part on GMU SWE 432 by Jeff Offutt, Thomas LaToza, and Jon Bell]

Asynchronous Programming Allow multiple things to happen at the same time An app is doing more than one thing at a time Maintain an interactive application while still doing something Processing data Communicating with remote servers/hosts Use threads A thread = a running program whose execution may be interleaved with other programs by the operating system Program execution = a series of sequential method calls

Multi-Threading Allow more than one things to be run at once (i.e., asynchronous) Typically handled by multiple OS scheduler Everything (you write) will run in a single thread (i.e., event loop) Event loop processes events and calls the callback functions Program execution = a series of sequential method calls event queue thread1 thread2 thread3 threadn event loop …

Event Loop Event queue Response from google.com thread1 thread2 thread3 threadn … queue Event queue Program execution = a series of sequential method calls Response from google.com Response from twitter.com Response from uva.com

Event Loop Event queue Event being processed Response from twitter.com thread1 thread2 thread3 threadn … queue Event queue Program execution = a series of sequential method calls Response from twitter.com Response from uva.com Event being processed Response from google.com Are there any listeners registered for this event? If so, call listener with event. After the listener is finished, repeat

Event Loop Event queue Event being processed Response from uva.com thread1 thread2 thread3 threadn … queue Event queue Program execution = a series of sequential method calls Response from uva.com Event being processed Response from twitter.com Are there any listeners registered for this event? If so, call listener with event. After the listener is finished, repeat

Writing Good Event Handler Events are processed in the order they are received Events may arrive in unexpected order The next event will not be handled until your event handler finishes (“run-to-completion”) Event must not block (stall or wait for inputs such as alert() or non-asynchronous request) If something that takes a long time must be done, split it up into multiple events