Outline for this evening

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Procedure Calls Prof. Sirer CS 316 Cornell University.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Stacks and HeapsCS-3013 A-term A Short Digression on Stacks and Heaps CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Digression on Stack and Heaps CS-502 (EMC) Fall A Short Digression on Stacks and Heaps CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
CS 536 Spring Code generation I Lecture 20.
CS 3013 & CS 502 Summer 2006 Digressions:– Producer-Consumer and Stacks 1 Two Digressions Stacks Producer-Consumer models.
Run-Time Storage Organization
Processes 1 CS502 Spring 2006 Processes Week 2 – CS 502.
More on FunctionsCS-2301 B-term More on Functions CS-2301, System Programming for Non-majors (Slides include materials from The C Programming Language,
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Digression: the “Stack” 1 CS502 Spring 2006 Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n
Stacks and HeapsCS-502 Fall A Short Digression Stacks and Heaps CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Recursion and Function Implementation CS-2301 D-term Recursion and Implementation of Functions CS-2301 System Programming C-term 2009 (Slides include.
Recursion and Implementation of Functions
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
Stacks & Recursion. Stack pushpop LIFO list - only top element is visible top.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
CSC 8505 Compiler Construction Runtime Environments.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
Chapter 14 Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Declarations (aka prototype) int.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
RecursionCIS 1057 Fall Recursion CIS 1057 Computer Programming in C Fall 2013 (Many slides based on/borrowed from Professor Hugh C. Lauer. Slides.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Chapter 14 Functions.
Storage Allocation Mechanisms
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Run-Time Environments Chapter 7
Processes and threads.
Functions.
Computer structure: Procedure Calls
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
The Stack.
Operating Systems (CS 340 D)
Mechanism: Limited Direct Execution
Chapter 3: Process Concept
CS41B recursion David Kauchak CS 52 – Fall 2015.
Chapter 14 Functions.
Recursion, Tail Recursion
Operating Systems (CS 340 D)
Chapter 10 The Stack.
Chapter 9 :: Subroutines and Control Abstraction
More examples How many processes does this piece of code create?
Stack Frame Linkage.
Recursion Data Structures.
Operating System Concepts
10/4: Lecture Topics Overflow and underflow Logical operations
Recursion and Implementation of Functions
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Procedures and Calling Conventions
Lecture 6: Multiprogramming and Context Switching
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Where is all the knowledge we lost with information? T. S. Eliot
Chapter 3: Process Concept
Chapter 14 Functions.
Return-to-libc Attacks
Chapter 14 Functions.
Implementing Functions: Overview
Presentation transcript:

Outline for this evening Comments on Programming Project #1 Two digressions Stacks Producer-Consumer models Inter-process Communication Linking & Loading Memory Management If enough time Programming Project #2 assignment CS-502 Fall 2006 Two Digressions

Stacks Producer-Consumer models Two Digressions Stacks Producer-Consumer models CS-502 Fall 2006 Two Digressions

Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n <= 1) return (1); else int y = factorial(n-1); return (y * n); } Imagine also the caller:– int x = factorial(100); What does compiled code look like? CS-502 Fall 2006 Two Digressions

Compiled code: the caller int x = factorial(100); Put the value “100” somewhere that factorial can find Put the current program counter somewhere so that factorial can return to the right place in caller Provide a place to put the result, so that caller can find it CS-502 Fall 2006 Two Digressions

Compiled code: factorial function Save the caller’s registers somewhere Get the argument n from the agreed-upon place Set aside some memory for local variables and intermediate results – i.e., y, n - 1 Do whatever it was programmed to do Put the result where the caller can find it Restore the caller’s registers Transfer back to the program counter saved by the caller CS-502 Fall 2006 Two Digressions

Question: Where is “somewhere”? So that caller can provide as many arguments as needed (within reason)? So that called routine can decide at run-time how much temporary space is needed? So that called routine can call any other routine, potentially recursively? CS-502 Fall 2006 Two Digressions

Answer: a “Stack” Stack – a linear data structure in which items are added and removed in last-in, first-out order. Calling program Push arguments & return address onto stack After return, pop result off stack CS-502 Fall 2006 Two Digressions

“Stack” (continued) Called routine Push registers and return address onto stack Push temporary storage space onto stack Do work of the routine Pop registers and temporary storage off stack Leave result on stack Return to address left by calling routine CS-502 Fall 2006 Two Digressions

Stack (continued) Definition: context – the region of the stack that provides the execution environment of a call to a function Implementation Usually, a linear piece of memory and a stack pointer contained in a (fixed) register Occasionally, a linked list Recursion Stack discipline allows multiple contexts for the same function in the stack at the same time CS-502 Fall 2006 Two Digressions

Questions? CS-502 Fall 2006 Two Digressions

Producer-Consumer Model Definition: a method by which one process communicates a (potentially infinite) stream of data through a finite buffer. Buffer:– a temporary storage area for data Esp. an area by which two processes (or computational activities) at different speeds can be decoupled from each other CS-502 Fall 2006 Two Digressions

Example – Ring Buffer Consumer empties items, starting with first full item empty empty empty empty empty empty Item i Item I+2 Item i+1 Item i+3 Item I+4 First item First free Producer fills items, starting with first free slot CS-502 Fall 2006 Two Digressions

Implementation with Semphores struct Item { … }; Item buffer[n]; semaphore empty = n, full = 0; Producer: int j = 0; while (true) { wait_s(empty); produce(buffer[j]); post_s(full); j = (j+1) mod n; } Consumer: int k = 0; while (true) { wait_s(full); consume(buffer[k]); post_s(empty); k = (k+1) mod n; } CS-502 Fall 2006 Two Digressions

Real-world example I/O overlapped with computing Producer: the input-reading process: Reads data as fast as device allows Waits for physical device to transmit records Unbuffers blocked records into ring buffer Consumer Computes on each record in turn Is freed from the details of waiting and unblocking physical input CS-502 Fall 2006 Two Digressions

Example (continued) Consumer Producer CS-502 Fall 2006 Two Digressions

Summary: Producer-Consumer Occurs frequently throughout computing Needed for decoupling the timing of two activities Uses whatever synchronization mechanism is available CS-502 Fall 2006 Two Digressions

Questions? Next topic CS-502 Fall 2006 Two Digressions