6/13/20151 CS 160: Lecture 13 Professor John Canny Fall 2004.

Slides:



Advertisements
Similar presentations
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Advertisements

OS/2 Warp Chris Ashworth Cameron Davis John Weatherley.
EEE 435 Principles of Operating Systems Principles and Structure of I/O Software (Modern Operating Systems 5.2 & 5.3) 5/22/20151Dr Alain Beaulieu.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
1 Model View Controller. 2 Outline Review Definitions of MVC Why do we need it? Administiriva Changing the display Event flow Dragging at interactive.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Graphical User Interface (GUI) Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
0 CS 160: Design Process: Implement Event-based UI Programming, Model-View-Controller, and the Web Jeffrey Nichols IBM Almaden Research Center
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Object-Oriented Analysis and Design
1 I/O Management in Representative Operating Systems.
Stanford hci group / cs376 research topics in human-computer interaction UI Software Tools Scott Klemmer 27 October 2005.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
2.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 2: Computer-System Structures Computer System Operation I/O Structure.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
2: Computer-System Structures
Threaded Applications Introducing additional threads in a Delphi application is easy.
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
Games Development 2 Concurrent Programming CO3301 Week 9.
Web Application Design Patterns. Large Scale Architectures Early systems were monolithic applications –Large and hard to maintain Then came the client-server.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Kernel Locking Techniques by Robert Love presented by Scott Price.
CS160 Discussion Section Matthew Kam Apr 7, 2003.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Model-View-Controller Architecture. 2 Give someone a program, you frustrate them for a day; teach them how to program, you frustrate them for a lifetime.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems Concepts
Chapter 3: Windows7 Part 5.
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Windows7 Part 5.
Module 2: Computer-System Structures
Professor John Canny Spring 2004 March 3
Process Description and Control
Threads Chapter 4.
Concurrency: Mutual Exclusion and Process Synchronization
Professor John Canny Spring 2004 March 5
Process Description and Control
Module 2: Computer-System Structures
Professor John Canny Spring 2003 March 12
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Presentation transcript:

6/13/20151 CS 160: Lecture 13 Professor John Canny Fall 2004

6/13/20152 Outline 4 Model-view controller *Why do we need it? *Changing the display *Event flow *Dragging at interactive speeds 4 Interactive application programming *Callbacks *Multi-threaded programming

6/13/20153 Model-View-Controller 4 Architecture for interactive apps *introduced by Smalltalk developers at PARC 4 Partitions application in a way that is *scalable *maintainable Model View Controller

6/13/20154 Example Application Blue circles: 4 Cardinal squares: 2

6/13/20155 Model 4 Information the app is trying to manipulate 4 Representation of real world objects *circuit for a CAD program +logic gates and wires connecting them *shapes in a drawing program +geometry and color Model View Controller

6/13/20156 View 4 Implements a visual display of the model 4 May have multiple views *e.g., shape view and numerical view Model View Controller

6/13/20157 Multiple Views Blue circles: 4 Cardinal squares: 2

6/13/20158 View 4 Implements a visual display of the model 4 May have multiple views *e.g., shape view and numerical view 4 Any time the model is changed, each view must be notified so that it can change later *e.g., adding a new shape Model View Controller

6/13/20159 Controller 4 Receives all input events from the user 4 Decides what they mean and what to do *communicates with view to determine which objects are being manipulated (e.g., selection) *calls model methods to make changes on objects +model makes change and notifies views to update Model View Controller

6/13/ Controller Blue circles: 4 Cardinal squares: 2

6/13/ Controller Blue circles: 4 Cardinal squares: 2

6/13/ Relationship of View & Controller “pattern of behavior in response to user events (controller issues) is independent of visual geometry (view issues)” 4 Controller must contact view to interpret what user events mean (e.g., selection)

6/13/ Combining View & Controller 4 View and controller are tightly intertwined *lots of communication between the two 4 Almost always occur in pairs *i.e., for each view, need a separate controller 4 Many architectures combine into a single class Model View Controller

6/13/ Why MVC? 4 Combining MVC into one class or using global variables will not scale *model may have more than one view +each is different and needs update when model changes 4 Separation eases maintenance *easy to add a new view later *new model info may be needed, but old views still work *can change a view later, e.g., draw shapes in 3-d (recall, view handles selection)

6/13/ Presentations next Mon-Weds 4 Monday groups Weds groups 6-10

6/13/ Adding Views Later Blue circles: 4 Cardinal squares: 2

6/13/ Changing the Display 4 How do we redraw when shape moves?

6/13/ Moving Cardinal Square Blue circles: 4 Cardinal squares: 2

6/13/ Erase w/ Background Color and Redraw Blue circles: 4 Cardinal squares: 2

6/13/ Changing the Display 4 Erase and redraw *using background color to erase fails *drawing shape in new position loses ordering 4 Move in model and then redraw view *change position of shapes in model *model keeps shapes in a desired order *tell all views to redraw themselves in order *slow for large / complex drawings +flashing!

6/13/ Damage / Redraw Method 4 View informs windowing system of areas that need to be updated (i.e., damaged) *does not redraw them at this time… 4 Windowing system *batches updates *clips them to visible portions of window 4 Next time waiting for input *windowing system calls Redraw method for win. +passes region that needs to be updated

6/13/ Damage old, Change position in model, Damage new Blue circles: 4 Cardinal squares: 2

6/13/ Event Flow 4 Creating a new shape

6/13/ Event Flow (cont.) 4 Assume blue circle selected Blue circles: 0 Cardinal squares: 0

6/13/ Event Flow (cont.) 4 Press mouse over tentative position 4 Windowing system identifies proper window for event 4 Controller for drawing area gets mouse click event 4 Checks mode and sees “circle” 4 Calls models AddCircle method with new position Blue circles: 0 Cardinal squares: 0

6/13/ Event Flow (cont.) 4 AddCircle adds new circle to model’s list of objects 4 Model then notifies list of views of change *drawing area view and text summary view 4 Views notifies windowing system of damage *both views notify WS without making changes yet! +model may override Blue circles: 0 Cardinal squares: 0

6/13/ Event Flow (cont.) 4 Views return to model, which returns to controller 4 Controller returns to event handler 4 Event handler notices damage requests pending and responds 4 If one of the views was obscured, it would be ignored Blue circles: 0 Cardinal squares: 0

6/13/ Event Flow (cont.) 4 Event handler calls view’s Redraw methods with damaged area 4 Views redraw all objects in model that are in damaged area Blue circles: 1 Cardinal squares: 0

6/13/ Dragging at Interactive Speeds 4 Damage old, move, damage new method may be too slow *must take less than 200 ms to be smooth 4 Solutions *don’t draw object, draw an outline (cartoon) +use XOR to erase fast (problems w/ color) +save portion of frame buffer before dragging

6/13/ Break 4 Next week presentations: 4 Monday: groups Wednesday: groups 6-10

6/13/ Interactive programming 4 Callbacks 4 Threading

6/13/ Callbacks 4 Callbacks: every widget registers itself to receive certain events with the OS. 4 Dangers: UI code using callbacks is usually single-threaded. Control does not return to the event loop until the callback returns. Therefore in a callback routine, never: *Wait for another event. *Sleep. *Perform I/O or other actions that may block.

6/13/ HE Principles: 4 User control and freedom 4 Visibility of system status 4 Help, 4 diagnosing errors

6/13/ Threaded code 4 Multi-threaded code uses distinct threads for distinct widgets. 4 It allows blocking operations (e.g. I/O) to be confined to particular threads that don’t affect interactivity. 4 If your program has any time-intensive parts, they should run in different threads from the UI code.

6/13/ Threaded code 4 Use separate threads for any operations that can occur asynchronously: *UI interactions. *File operations – use separate threads if you need to be updating several files at the same time. *Inter-process communication (sockets): use one thread for each connection. *Use a thread for each other I/O device, e.g. one each for reading from or writing to the sound card.

6/13/ Inter-thread communication 4 The window system and running process in the OS communicate using message passing: *The event queue and sockets are examples of message-passing primitives. 4 Processes in the same address space (i.e. within your program) can use shared memory (i.e. shared variables) which is much more efficient.

6/13/ Inter-thread communication 4 Why can’t thread A call thread B (like a callback?)

6/13/ Synchronization 4 Shared-memory communication poses challenges. If you rely on “mailbox” primitives, things can go wrong: 0 Flag to show this thread is writing new data Data

6/13/ Synchronization Intuitively, threads that want to write should: …. wait until thread_id = 0; write thread_id; write data; 0 Data Flag to show this thread is writing new data

6/13/ Synchronization But thread switching can happen anytime, e.g. …. wait until thread_id = 0; write thread_id; write data; 0 Data Flag to show this thread is writing new data

6/13/ Synchronization A switch between checking the flag and setting it allows both threads to (incorrectly) write the flag and their data. To prevent this, we define critical sections of the code that cannot be interrupted. 0 Data Flag to show this thread is writing new data

6/13/ Synchronization e.g. the critical section in the example is: …. wait until thread_id = 0; write thread_id; write data; 0 Data Critical section, thread can’t be pre-empted. Flag to show this thread is writing new data

6/13/ Semaphores Rather than many critical sections in your code, you can use a single semaphore primitive. A semaphore is initialized to an integer n, and has just two operations: test(); wait until semaphore > 0, then decrement it. increment(); increment the semaphore.

6/13/ Semaphore example Then the example code becomes (with sem1 initialized to 1): …. sem1.test(); write thread_id; write data; sem1.increment(); This section cannot be pre-empted by the other process that is using this semaphore.

6/13/ Summary 4 Model-view controller *Why do we need it? *Changing the display *Event flow *Dragging at interactive speeds 4 Interactive application programming *Callbacks *Multi-threaded programming