CS533 - Concepts of Operating Systems 1 Threads, Events, and Reactive Objects - Alan West.

Slides:



Advertisements
Similar presentations
Categories of I/O Devices
Advertisements

Concurrent Programming James Adkison 02/28/2008. What is concurrency? “happens-before relation – A happens before B if A and B belong to the same process.
CS 443 Advanced OS Fabián E. Bustamante, Spring 2005 Resource Containers: A new Facility for Resource Management in Server Systems G. Banga, P. Druschel,
Remote Procedure Call (RPC)
Threads, Events, and Scheduling Andy Wang COP 5611 Advanced Operating Systems.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Concurrency CS 510: Programming Languages David Walker.
CS533 Concepts of Operating Systems Class 2 Thread vs Event-Based Programming.
©Brooks/Cole, 2003 Chapter 7 Operating Systems Dr. Barnawi.
Concurrency, Threads, and Events Robbert van Renesse.
CS533 - Concepts of Operating Systems 1 CS533 Concepts of Operating Systems Class 8 Synchronization on Multiprocessors.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
The Structuring of Systems Using Upcalls David D. Clark 4/26/20111Frank Sliz, CS533, Upcalls.
The Structuring of Systems Using Upcalls David D. Clark Presenter: Haitham Gad.
Why Threads Are A Bad Idea (for most purposes) John Ousterhout Sun Microsystems Laboratories
Fundamentals of Python: From First Programs Through Data Structures
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
CS252: Systems Programming Ninghui Li Final Exam Review.
Computer System Architectures Computer System Software
University of Pittsburgh Computer Science 1 Week 5: Introduction Last week we discussedLast week we discussed èDifference between executing sequentially.
CS 153 Design of Operating Systems Spring 2015
Institute of Computer and Communication Network Engineering OFC/NFOEC, 6-10 March 2011, Los Angeles, CA Lessons Learned From Implementing a Path Computation.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
A Revolutionary Programming Pattern that Will Clean up your Code : Coroutines in C++ David Sackstein ACCU 2015.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Proactor Pattern Venkita Subramonian & Christopher Gill
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
Debugging Threaded Applications By Andrew Binstock CMPS Parallel.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan
CS533 Concepts of Operating Systems Jonathan Walpole.
Concurrent Object-Oriented Programming Languages Chris Tomlinson Mark Scheevel.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Parallel Computation of Skyline Queries Verification COSC6490A Fall 2007 Slawomir Kmiec.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Channels. Models for Communications Synchronous communications – E.g. Telephone call Asynchronous communications – E.g. .
Computer Science Lecture 4, page 1 CS677: Distributed OS Last Class: RPCs RPCs make distributed computations look like local computations Issues: –Parameter.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Sockets A popular API for client-server interaction.
Chapter 4: Threads.
Chapter 3: Process Concept
“Language Mechanism for Synchronization”
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Chapter 3 Internet Applications and Network Programming
Threads, Events, and Scheduling
#01 Client/Server Computing
Client-Server Interaction
GEOMATIKA UNIVERSITY COLLEGE CHAPTER 2 OPERATING SYSTEM PRINCIPLES
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
CS 501: Software Engineering Fall 1999
Issues in Client/Server Programming
Lecture 2 Part 2 Process Synchronization
Threads, Events, and Scheduling
Channels.
Design Components are Code Components
Structuring Of Systems Using Upcalls - By David D. Clark
Concurrency: Mutual Exclusion and Process Synchronization
Threaded Programming in Python
Threads, Events, and Scheduling
Why Threads Are A Bad Idea (for most purposes)
Channels.
Foundations and Definitions
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
Chapter 13: I/O Systems.
#01 Client/Server Computing
Presentation transcript:

CS533 - Concepts of Operating Systems 1 Threads, Events, and Reactive Objects - Alan West

CS533 - Concepts of Operating Systems 2 Overview  Threads… Bad Idea  Traditional view of I/0 and why today’s environment doesn’t facilitate it well  Event-based programming model o Implemented with threads o Implemented with reactive object  Example: Reactive Objects in Timber

CS533 - Concepts of Operating Systems 3 Threads… Bad Idea  Threads used for: o Operating systems - one thread per process o Scientific Applications - one thread per CPU o Distributed Systems - process requests concurrently o GUIs - window events, mouse clicks, key clicks  Overkill for distributed systems and GUIs when true concurrency is not usually needed  Hard to program o Synchronization of shared data o Risk of deadlock

CS533 - Concepts of Operating Systems 4 Threads… Bad Idea cont.  Hard to debug o Timing dependencies  Performance degrades o Remember last class? Locks = significant overhead  Support for threads poor o Low portability o Thread-safe? o Few debugging tools. Remember Eraser?

CS533 - Concepts of Operating Systems 5 Solution: Event-based programming  True concurrency not need in many cases… So, use event based programming  One stream of execution  Event loop waits for events and invokes handlers  No preemption of event handlers  Handlers generally short-lived  Good for GUI’s and distributed systems o One handler for each GUI event or source of input

CS533 - Concepts of Operating Systems 6 Now let’s talk I/0: The traditional view  Assumption that environment is centrally controlled and synchronous  Transparent blocking  Interactions with environment through blocking subroutine calls  Batch-oriented

CS533 - Concepts of Operating Systems 7 Today’s environment is complex  GUI’s  Distributed networks  Multiple threads of execution  Environment is not centrally controlled  Asynchronous events occur at random

CS533 - Concepts of Operating Systems 8 Implement events with threads?  Each event (or types of events) could be handled by one threads.  Example: Mouse/Key clicks handled by one thread and monitoring a network socket with another thread.  Usage of threads conforms well to the traditional view of I/O o Each thread simply conforms to batch-oriented I/O

CS533 - Concepts of Operating Systems 9 Problems with using threads to implement events  Threads are hard (as mentioned before)  Threads used for events is not what threads were designed for o Events do not generally imply the need for concurrent execution. So, separate threads per event instead achieve concurrent blocking.  Threads are simply being used to circumvent an “inappropriate I/O model”.  Threads are harmful to the responsiveness of the program. A thread handling a certain event could potentially block and lead to missed events.  “Heavy encodings needed to turn even simple event- driven models into working code is most unfortunate”

CS533 - Concepts of Operating Systems 10 Reactive Objects  Takes an object-oriented approach to handling events  Provides a single object that is capable of handling all the various events a program is required to handle (e.g. mouse clicks, network packets)  Input: Environment calls a method of a program object. Input is a reaction.  Output: Program calls a method of an environment object. Output is a concrete act of the program.

CS533 - Concepts of Operating Systems 11 Reactive Objects cont.  A reactive object is capable of executing the sequential code of exactly one method at a time.  This ensures the integrity of data. Hence, gaining the benefits of a critical region.  Asynchronous vs. Synchronous method invocations o Send and forget w/ asynchronous. Sender and receiver continues executing in parallel. o Sender/receiver performs a rendezvous  Important restriction in reactive objects is that no methods must block execution indefinitely.

CS533 - Concepts of Operating Systems 12 Reactive Objects cont.  No continuous thread of execution  Methods guaranteed to terminate given deadlock is not encountered. However, deadlock can occur but only in a cyclic chain of synchronous method calls which is can be easily debugged.  Given that blocking methods are prohibited, responsiveness thrives.

CS533 - Concepts of Operating Systems 13 Reactive Objects vs. Monitors  Key difference is that concurrency in reactive objects is that only one method can be called at a time within a reactive object.  Monitors include calls that block (e.g. waiting on a condition).  Both provide encapsulation of shared data.

CS533 - Concepts of Operating Systems 14 Reactive Objects in Timber  Timber is a strongly typed, object oriented language that inherits much of its design from O’Haskell.  Ping: An example of reactive objects o Demonstrates how to concurrently measure the time it takes to connect to a number of remote hosts.  Sample output: o dogbert: ms ratbert: ms ratburg: NetError “lookup failure” theboss: no response  All methods in Ping are asynchronous.  Objects of Ping maintain the “outstanding” state variable which is a list of hosts

CS533 - Concepts of Operating Systems 15 Ping ping hosts port env = template outstanding := hosts in let client host start peer = record connect = action env.putStrLn(host++": "++show(baseline-start)) outstanding := remove host outstanding peer.close neterror err = action env.putStrLn(host++": "++show err) outstanding := remove host outstanding deliver pkt = action done close = action done cleanup = action forall h <- outstanding do env.putStrLn(h++": no response") env.quit in record main = action forall h <- hosts do env.inet.tcp.open h port (client h baseline) after (2*seconds) Things to note:  inet.tcp.open initiates TCP connection  No where does this code block  Program does not wait for connection to be established

CS533 - Concepts of Operating Systems 16 Conclusions  Reactive objects provide simple/natural model of event driven systems.  Contains encapsulated state and provides the benefits of a critical region.  Threads are hard to program with and should only be used when concurrent execution is truly needed.  Therefore, reactive objects are a better solution for event driven systems.