CS11 Advanced C++ Spring Lecture 9 (!!!)
|
|
|
- Shannon Houston
- 9 years ago
- Views:
Transcription
1 CS11 Advanced C++ Spring Lecture 9 (!!!)
2 The static Keyword C++ provides the static keyword Also in C, with slightly different usage Used in two main contexts: Declaring static members of a class Declaring static local variables within functions Both uses are very helpful in certain situations
3 Class Members Class-members are usually associated with objects class Matrix4F { float values[16]; public: bool isorthogonal() { } }; Each matrix-object has its own copy of values member Calling isorthogonal() requires a specific object Matrix4F m = ; if (m.isorthogonal()) m.transpose(); // can invert by transposing
4 Static Members Might want to provide constants for our class Only want one copy of the constant for the entire class, not one per object! Also might want to provide general utility functions for our class Functions that help with the class, but don t need to be called on a specific object Static class-members aren t associated with a specific object The member is associated with the class itself, not with individual objects
5 Static Constants Add an Identity constant to our matrix class Updated declaration, in our matrix.hh file: class Matrix4F { public: // Identity matrix constant static const Matrix4F Identity; }; Static member is not defined or initialized in the declaration! Separately initialized in corresponding matrix.cc file (reasons are gross and involve compilation/linking issues)
6 Static Constants (2) Within the corresponding matrix.cc file: const Matrix4F Matrix4F::Identity = Matrix4F().setIdentity(); Only use static keyword in declaration, not in definition Refer to static member by its qualified name: Matrix4F::Identity To use default initialization for static member: const Matrix4F Matrix4F::Identity; Still must appear in the.cc file! Otherwise, linker errors Other code can refer to the static constant: #include "matrix.hh" if (m == Matrix4F::Identity)
7 Static Functions Add a static function to convert Euler angles into corresponding transform matrix class Matrix4F { public: static Matrix4F geteulertransform( const EulerAngles &a); }; Function definition can appear in class declaration or in definition (only static member-variables are finicky)
8 Static Functions (2) Can call static function without requiring an object #include "matrix.hh" Matrix4F m; EulerAngles a; m = Matrix4F::getEulerTransform(a); Use qualified name to refer to static member-function Within the Matrix4F class definition, don t even need fully qualified name to refer to static member
9 Local Variables Within functions, local variables are initialized when execution reaches each variable s declaration float compute(float a, float b) { float result = 0; // result is initialized if (a < b) { result = a * b; } else { float c = 0.1 * (a b); // c is initialized result = c * compute(a c, b + c); } return result; } Every time execution reaches a variable declaration, that variable is initialized
10 Static Local Variables Can also declare static local variables Initialized once, when execution reaches the variable s declaration for the first time Variable s value is remembered between calls! Example: function to get a unique ID int GetNextID() { static int nextid = 10000; int id = nextid; nextid++; return id; } At first call, nextid is initialized to Variable remembers its value across multiple function calls
11 Static Local Variables and Concurrency Static local variables break concurrent execution Reentrant functions functions that can be called from multiple concurrent threads of execution Static state must be guarded with mutexes, or function will not generate correct results (For reentrant functions, better to just avoid static state!) Our unique ID function: int GetNextID() { static int nextid = 10000; int id = nextid; nextid++; return id; } All these operations need to be guarded for correct concurrent execution. Concurrent calls from different threads can easily produce the same ID, or not update nextid properly.
12 Singletons A very common design pattern: Singleton Ensure a class has only one instance, and provide a global point of access to it. Design Patterns, Gamma et al. Some examples: Only one window manager in an operating system Only one system clock Only one filesystem manager Frequently run into singletons in practice Manager or factory classes often singletons
13 Implementing Singletons Two main problems to solve: Ensure a class has only one instance. Provide a global point of access to it. Not terribly hard problems to solve, but some ways are better than others Might want to avoid creating the singleton object until it s actually needed If singleton object manages system resources then destructor must be called at proper time! Will singleton be used from multiple threads?
14 First Task: Only One Instance Create our singleton class: class Singleton { public: Singleton() { } ~Singleton() { } int getimportantvalue(); }; How can we ensure only one copy? Need to hide the constructor make it private Also need to hide the copy-constructor Prevent callers from getting the instance, then copying it!
15 Private Constructors Updated singleton class: class Singleton { // Make constructor private. Singleton() { } // Make copy-constructor private; disallow copying. Singleton(const Singleton &) { assert(false); } public: ~Singleton() { } int getimportantvalue(); }; What about the destructor? Don t want a caller to get the instance and then destroy it! Make the destructor private too.
16 Private Destructor Updated singleton class: class Singleton { // Make constructor and destructor private. Singleton() { } ~Singleton() { } // Make copy-constructor private; disallow copying. Singleton(const Singleton &) { assert(false); } public: int getimportantvalue(); }; Now the Singleton class has total control over its own lifecycle
17 Singletons and Assignment What about assignment? class Singleton { // Make constructor and destructor private. Singleton() { } ~Singleton() { } // Make copy-constructor private; disallow copying. Singleton(const Singleton &) { assert(false); } public: int getimportantvalue(); }; If there is only one instance of Singleton then all assignment is self-assignment. Don t really need assignment, so make that private too.
18 Singletons and Assignment (2) Updated singleton class: class Singleton { // Make constructor and destructor private. Singleton(); ~Singleton(); // Make copy-constructor private; disallow copying. Singleton(const Singleton &) { assert(false); } // Make assignment-operator private, and disallow. void operator=(const Singleton &) { assert(false); } }; All these are in the private section of singleton class
19 Storing the Single Instance Singleton class has strict control over its lifecycle now Still need to store the single instance somewhere Two obvious options: Make a static Singleton object Make a static Singleton pointer
20 Static Singleton Object A static singleton object: class Singleton { static Singleton instance; public: // Provide access to the singleton. static Singleton & Instance() { return instance; } }; This is in the header file singleton.hh Source file singleton.cc initializes the instance: // Initialize singleton with default constructor. Singleton Singleton::instance;
21 Static Singleton Object (2) This technique relies on dynamic initialization // Initialize singleton with default constructor. Singleton Singleton::instance; instance is initialized with a constructor-call, not with a compile-time constant When does this initialization occur? High-level, hand-wavey answer: Within the code generated from singleton.cc, dynamic initialization of static objects is done first. Called a translation unit by the specification When multiple translation units are involved, situation becomes ambiguous! Can t guarantee order that translation units are initialized
22 Static Singleton Object (3) In another source-file fubar.cc, you have a global variable: int ImportantValue = Singleton::Instance().getImportantValue(); Separate translation unit with its own dynamic initialization No guarantee that instance has been initialized when accessed from the other module! Compiler may have chosen to initialize fubar.cc s translation unit before singleton.cc s translation unit Moral: Don t use non-local static singleton objects, or you will be sad.
23 Static Singleton Pointer Instead of storing an object, store a static pointer: class Singleton { static Singleton *pinstance; public: // Provide access to the singleton. static Singleton & Instance() { if (!pinstance) // Need to construct! pinstance = new Singleton(); return *pinstance; } }; Again, in singleton.cc we have: Singleton *Singleton::pInstance = 0;
24 Static Singleton Pointer (2) Two benefits over static singleton-object approach! Singleton instance is only constructed when it s actually needed Especially useful if singleton construction is expensive Doesn t suffer from dynamic-initialization issues Singleton-pointer is statically initialized to 0 right when the module is loaded into memory No dynamic operations needed No issues with calls from other translation units int ImportantValue = Singleton::Instance().getImportantValue();
25 Static Singleton Pointer (3) Still one problem though How do we call the destructor on our singleton object? Memory management is not the issue: When the process terminates, OS can reclaim all memory allocated by the process Many other resources cannot be reclaimed by OS! Shared memory is notorious: requires a reboot. Semaphores, other inter-process communication resources Low-level networking resources Hmm, we need to call that destructor. Static singleton pointers aren t so cool after all.
26 Static Local Singletons One other way to create a singleton object: class Singleton { // No static singleton members! public: static Singleton & Instance() { static Singleton instance; return instance; } }; instance is constructed the first time execution passes through the variable declaration Value of instance is remembered between calls A very simple and elegant way of creating a singleton!
27 Static Local Singletons (2) C++ standard is wonderfully clear about static local objects! class Singleton { static Singleton & Instance() { static Singleton instance; // static local object return instance; } }; Static local objects are constructed the first time execution passes through the variable declaration Exactly what we need for lazy initialization C++ also registers a destructor call for static local objects Destructor is always called at process termination!
28 Static Local Singletons (3) This technique still has issues with multithreading: class Singleton { static Singleton & Instance() { static Singleton instance; return instance; } }; Compiler effectively manages a Boolean flag that tracks whether instance has been initialized Access from multiple threads can cause multiple constructor calls on instance not good. Easier to solve efficiently when using the more explicit singleton-pointer approach, using a mutex. Look up double-checked locking
29 Singletons: A Summary Provide a static accessor the global access point These standard operations are made private: Constructor Destructor Copy-constructor (don t support) Assignment operator (don t support) Several ways to create singleton objects For single-threaded use, static local object approach is simple and clean For multithreaded use, static pointer approach is easier to make correct Avoid static object approach prone to nasty failures!
30 Singleton References More Effective C++, Item 26 Scott Meyers The static local object approach Modern C++ Design, Chapter 6 Andrei Alexandrescu A broad and deep coverage of all singleton patterns and major design considerations A great book for advanced C++ techniques in general! Buy it!
C++ Overloading, Constructors, Assignment operator
C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang
6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang Today s topics Why objects? Object-oriented programming (OOP) in C++ classes fields & methods objects representation
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
Object Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Object Oriented Software Design II
Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
El Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=
CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= We already know that the compiler will supply a default (zero-argument) constructor if the programmer does not specify one.
Stack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
Monitors, Java, Threads and Processes
Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Real Time Programming: Concepts
Real Time Programming: Concepts Radek Pelánek Plan at first we will study basic concepts related to real time programming then we will have a look at specific programming languages and study how they realize
Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.
The Secret Partner Pattern Revision 3a by Bill Trudell, July 23, 2001 Submitted to the Pattern Languages of Programs Shepherd: Neil Harrison PC Member: Kyle Brown Thumbnail This paper describes the Secret
C++ Crash Kurs. C++ Object-Oriented Programming
C++ Crash Kurs C++ Object-Oriented Programming Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ classes A class is user-defined type
language 1 (source) compiler language 2 (target) Figure 1: Compiling a program
CS 2112 Lecture 27 Interpreters, compilers, and the Java Virtual Machine 1 May 2012 Lecturer: Andrew Myers 1 Interpreters vs. compilers There are two strategies for obtaining runnable code from a program
Lecture 6: Semaphores and Monitors
HW 2 Due Tuesday 10/18 Lecture 6: Semaphores and Monitors CSE 120: Principles of Operating Systems Alex C. Snoeren Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks
Chapter 13 Storage classes
Chapter 13 Storage classes 1. Storage classes 2. Storage Class auto 3. Storage Class extern 4. Storage Class static 5. Storage Class register 6. Global and Local Variables 7. Nested Blocks with the Same
Input/Output Subsystem in Singularity Operating System
University of Warsaw Faculty of Mathematics, Computer Science and Mechanics Marek Dzikiewicz Student no. 234040 Input/Output Subsystem in Singularity Operating System Master s Thesis in COMPUTER SCIENCE
CORBA Programming with TAOX11. The C++11 CORBA Implementation
CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy
COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.
COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation
No no-argument constructor. No default constructor found
Every software developer deals with bugs. The really tough bugs aren t detected by the compiler. Nasty bugs manifest themselves only when executed at runtime. Here is a list of the top ten difficult and
REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux
REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux Lesson-12: Real Time Linux 1 1. Real Time Linux 2 Linux 2.6.x Linux is after Linus Torvalds, father of the Linux operating
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to Classes Classes as user-defined types We have seen that C++ provides a fairly large set of built-in types. e.g
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
Keil C51 Cross Compiler
Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
Code Qualities and Coding Practices
Code Qualities and Coding Practices Practices to Achieve Quality Scott L. Bain and the Net Objectives Agile Practice 13 December 2007 Contents Overview... 3 The Code Quality Practices... 5 Write Tests
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
Computer Programming C++ Classes and Objects 15 th Lecture
Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline
How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)
TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions
CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing
CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects
Variable Base Interface
Chapter 6 Variable Base Interface 6.1 Introduction Finite element codes has been changed a lot during the evolution of the Finite Element Method, In its early times, finite element applications were developed
Compile-time type versus run-time type. Consider the parameter to this function:
CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();
Basics of C++ and object orientation in OpenFOAM
Basics of C++ and object orientation in OpenFOAM To begin with: The aim of this part of the course is not to teach all of C++, but to give a short introduction that is useful when trying to understand
An Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators
CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators This handout is designed to provide a better understanding of how one should write template code and architect iterators
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Outline of this lecture G52CON: Concepts of Concurrency
Outline of this lecture G52CON: Concepts of Concurrency Lecture 10 Synchronisation in Java Natasha Alechina School of Computer Science [email protected] mutual exclusion in Java condition synchronisation
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
More C++ Concepts. Operator overloading Friend Function This Operator Inline Function
More C++ Concepts Operator overloading Friend Function This Operator Inline Function 1 Review There are different types of member functions in the definition of a class Accessor int Str :: get_length();
Recursion vs. Iteration Eliminating Recursion
Recursion vs. Iteration Eliminating Recursion continued CS 311 Data Structures and Algorithms Lecture Slides Monday, February 16, 2009 Glenn G. Chappell Department of Computer Science University of Alaska
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism
Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)
C and C++: Case Studies in Compatibility
C and C++: Case Studies in Compatibility Bjarne Stroustrup AT&T Labs Florham Park, NJ, USA ABSTRACT This article gives examples of how one might go about increasing the degree of compatibility of C and
Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions
COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement
Semantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
Introduction to Embedded Systems. Software Update Problem
Introduction to Embedded Systems CS/ECE 6780/5780 Al Davis logistics minor Today s topics: more software development issues 1 CS 5780 Software Update Problem Lab machines work let us know if they don t
Parameter passing in LISP
Parameter passing in LISP The actual parameters in a function call are always expressions, represented as lists structures. LISP provides two main methods of parameter passing: Pass/Call-by-value. The
CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014
CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages Nicki Dell Spring 2014 What is a Programming Language? A set of symbols and associated tools that translate (if necessary) collections
Priority Inversion Problem and Deadlock Situations
INTER-PROCESS COMMUNICATION AND SYNCHRONISATION: Lesson-11: Priority Inversion Problem and Deadlock Situations 1 1. Priority Inversion 2 Assume Priorities of tasks be in an order such that task I highest
Object Oriented Software Design II
Object Oriented Software Design II Real Application Design Christian Nastasi http://retis.sssup.it/~lipari http://retis.sssup.it/~chris/cpp Scuola Superiore Sant Anna Pisa April 25, 2012 C. Nastasi (Scuola
MPLAB Harmony System Service Libraries Help
MPLAB Harmony System Service Libraries Help MPLAB Harmony Integrated Software Framework v1.08 All rights reserved. This section provides descriptions of the System Service libraries that are available
6.S096 Lecture 1 Introduction to C
6.S096 Lecture 1 Introduction to C Welcome to the Memory Jungle Andre Kessler Andre Kessler 6.S096 Lecture 1 Introduction to C 1 / 30 Outline 1 Motivation 2 Class Logistics 3 Memory Model 4 Compiling 5
Tools Page 1 of 13 ON PROGRAM TRANSLATION. A priori, we have two translation mechanisms available:
Tools Page 1 of 13 ON PROGRAM TRANSLATION A priori, we have two translation mechanisms available: Interpretation Compilation On interpretation: Statements are translated one at a time and executed immediately.
SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)
SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics
Item 7: Prefer Immutable Atomic Value Types
Item 7: Prefer Immutable Atomic Value Types 1 Item 7: Prefer Immutable Atomic Value Types Immutable types are simple: After they are created, they are constant. If you validate the parameters used to construct
1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {
Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for
CS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 25 Multiple Inheritance and Interfaces Dan Grossman 2012 Multiple Inheritance Why not allow class C extends C1,C2,...{...} (and C C1 and C C2)? What everyone
Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture
Last Class: OS and Computer Architecture System bus Network card CPU, memory, I/O devices, network card, system bus Lecture 3, page 1 Last Class: OS and Computer Architecture OS Service Protection Interrupts
Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example
Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics
Compiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
C++FA 3.1 OPTIMIZING C++
C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have
CS11 Java. Fall 2014-2015 Lecture 7
CS11 Java Fall 2014-2015 Lecture 7 Today s Topics! All about Java Threads! Some Lab 7 tips Java Threading Recap! A program can use multiple threads to do several things at once " A thread can have local
Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding
Compiling Object Oriented Languages What is an Object-Oriented Programming Language? Last time Dynamic compilation Today Introduction to compiling object oriented languages What are the issues? Objects
Systemnahe Programmierung KU
S C I E N C E P A S S I O N T E C H N O L O G Y Systemnahe Programmierung KU A6,A7 www.iaik.tugraz.at 1. Virtual Memory 2. A7 - Fast-Food Restaurant 2 Course Overview A8, A9 System Programming A7 Thread
Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights
Outline Review Inter process communication Signals Fork Pipes FIFO Spotlights 1 6.087 Lecture 14 January 29, 2010 Review Inter process communication Signals Fork Pipes FIFO Spotlights 2 Review: multithreading
Java Memory Model: Content
Java Memory Model: Content Memory Models Double Checked Locking Problem Java Memory Model: Happens Before Relation Volatile: in depth 16 March 2012 1 Java Memory Model JMM specifies guarantees given by
Thread-Specific Storage for C/C++ An Object Behavioral Pattern for Accessing per-thread State Efficiently
Thread-Specific Storage for C/C++ An Object Behavioral Pattern for Accessing per-thread State Efficiently Douglas C. Schmidt Nat Pryce Timothy H. Harrison fschmidt, [email protected] [email protected]
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A
CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
Paper 3F6: Software Engineering and Systems Distributed Systems Design Solutions to Examples Paper 3
Engineering Tripos Part IIA THIRD YEAR Paper 3F: Software Engineering and Systems Distributed Systems Design Solutions to Examples Paper 3 CORBA 1. (a) A typical IDL file for this application is as follows:
Signals and Slots in C++
Signals and Slots in C++ Sarah Thompson March 2002 1 Introduction This paper introduces the sigslot library, which implements a type-safe, thread-safe signal/slot mechanism in C++. The library is implemented
Lecture 9. Semantic Analysis Scoping and Symbol Table
Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax
Chapter 12. Development Tools for Microcontroller Applications
Chapter 12 Development Tools for Microcontroller Applications Lesson 01 Software Development Process and Development Tools Step 1: Development Phases Analysis Design Implementation Phase 1 Phase 2 Phase
CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator=
CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator= Much of the surrounding prose written by Andy Maag, CS193D instructor from years ago. The compiler will supply a default (zero-argument)
Lecture 22: C Programming 4 Embedded Systems
Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human
Stock Trader System. Architecture Description
Stock Trader System Architecture Description Michael Stevens [email protected] http://www.mestevens.com Table of Contents 1. Purpose of Document 2 2. System Synopsis 2 3. Current Situation and Environment
MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00
MPLAB TM C30 Managed PSV Pointers Beta support included with MPLAB C30 V3.00 Contents 1 Overview 2 1.1 Why Beta?.............................. 2 1.2 Other Sources of Reference..................... 2 2
Description of Class Mutation Mutation Operators for Java
Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea [email protected] Jeff Offutt Software Engineering George Mason University
Building a Multi-Threaded Web Server
Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous
Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.
Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science [email protected] Names, Bindings, and Scopes A name is a symbolic identifier used
CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17
CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17 System Calls for Processes Ref: Process: Chapter 5 of [HGS]. A program in execution. Several processes are executed concurrently by the
Use of ROOT in Geant4
Use of ROOT in Geant4 A.Dotti, SLAC I. Hrivnacova, IPN Orsay W. Pokorski, CERN ROOT Users Workshop, 11-14 March 2013, Saas-Fee Outline Analysis tools in Geant4 Use of Root in Geant4 testing Experience
Singletons. The Singleton Design Pattern using Rhapsody in,c
Singletons Techletter Nr 3 Content What are Design Patterns? What is a Singleton? Singletons in Rhapsody in,c Singleton Classes Singleton Objects Class Functions Class Variables Extra Functions More Information
1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.
1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated
