Today Quiz not yet graded (Sorry!) More on Multithreading Happens-Before in Java Other langauges with Happens-Before Happens-Before in C++ SE-2811 Slide.

Slides:



Advertisements
Similar presentations
Concurrency 101 Shared state. Part 1: General Concepts 2.
Advertisements

Week 9, Class 3: Model-View-Controller Final Project Worth 2 labs Happens-Before ( SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
SE3910 Week 2, Class 2 Today Real-Time Systems Embedded Systems Other ??? Week 3 Tuesday Lab Lab start TBA SE-2811 Slide design: Dr. Mark L. Hornick Content:
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
CDP 2012 Based on “C++ Concurrency In Action” by Anthony Williams and The C++11 Memory Model and GCC WikiThe C++11 Memory Model and GCC Created by Eran.
Today TBA Tomorrow Good Friday SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 5, Class 3.
CDP 2013 Based on “C++ Concurrency In Action” by Anthony Williams, The C++11 Memory Model and GCCThe C++11 Memory Model and GCC Wiki and Herb Sutter’s.
SE1011 Week 2, Class 3 Today Compiling and running Another example using Scanner Compile-time and Run-time errors Review for exam SE-1011 Slide design:
CS2852 Week 2, Class 1 Today Generics (Section 051) Big-O runtime analysis Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See.
Today Networking in Linux/C Lab Eclipse cross-compiling Measuring latency of 100% CPU busy-wait polling Sleeping busy-wait polling Interrupt-driven response.
Today Quiz Multithreading Options Qt socket buffers between threads Quiz today & Tuesday in lab SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
Week 9, Class 3: Model-View-Controller Today Happens-Before Adapter and Façade Pattern (high-level) Tuesday: Project code due, 11pm Wednesday: Quiz Choose.
Today C/C++:.h/.cpp; compiling and linking Fourier Transform (corrected) Nyquist Theorem Audio sampling rates SE-2811 Slide design: Dr. Mark L. Hornick.
Week 3, Day 2: Threads Questions about Threads “Multithreading” in Swing Lab tomorrow: Quiz Lab 3: Threading! SE-2811 Slide design: Dr. Mark L. Hornick.
SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Use interrupts in a Linux/C environment – Scheduling – Watchdog follow-up Watchdog.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
COMPSCI 230 S2C 2015 Software Design and Construction Synchronization (cont.) Lecture 4 of Theme C.
CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Today Nervous System Response Time SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 3, Class 2.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Today Return Quiz Class Climate Survey Review SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 10, Class.
CS2852 Week 6, Class 1 Today The run-time stack Writing and proving recursive methods SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 5, Class 2 Today Queue Applications Circular Queue Implementation Testing SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 7, Class 1 Today Binary Search Tree Implementing add Implementing find Return Quiz 4 (second attempt) Both sections are graded SE-2811 Slide.
Today Return Quiz First release of final project template Multithreading Options Qt socket buffers between threads Tomorrow: Quiz Interthread communication.
Today Final Project “Preview” Real-time concurrency Multithreading Options pthreads qthreads GPIO.h & GPIO.cpp Quiz tomorrow & Tuesday in lab SE-2811 Slide.
CS2852 Week 6, Class 2 Today Class exercise: Implementing a recursive method Binary Search Trees Tomorrow: Quiz at start of lab Implementing a recursive.
Today Return Quiz First true release of final project (Lab 8) Multithreading Options Qt socket buffers between threads SE-2811 Slide design: Dr. Mark L.
Week 9, Class 3: Java’s Happens-Before Memory Model (Slides used and skipped in class) SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
The C++11 Memory Model CDP Based on “C++ Concurrency In Action” by Anthony Williams, The C++11 Memory Model and GCCThe C++11 Memory Model and GCC Wiki.
Today Quiz not yet graded Final report requirements posted More on Multithreading Happens-Before in Java SE-2811 Slide design: Dr. Mark L. Hornick Content:
CS2852 Week 3, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
Today Signals Nyquist Theorem (revisited) Audio Sampling Latency and Bandwidth Scheduling Theory SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
CS2852 Week 2, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
Today (or Thursday) Qt Thursday Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 6, Lab.
CS2910 Week 8, Class 2 Today Return Quiz Look at Schedule TCP implementation! Week 8, Monday Quiz on SMTP May include some questions requiring you to interpret.
CS2910 Week 7, Class 1 Today Capturing SMTP with Thunderbird Tomorrow Extra office hour at 11 am (right after lab) Friday Office hour cancelled SE-2811.
Week 6, Class 3: Composite Swing composites File composites Computer composites SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
Week 8, Class 3: Model-View-Controller Final Project Worth 2 labs Cleanup of Ducks Reducing coupling Finishing FactoryMethod Cleanup of Singleton SE-2811.
CS2910 Week 6, Lab Today Dictionaries in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
SE3910 Week 8, Class 2 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 7, Class 2 (Wednesday) Half-Exam 2 Done.
SE3910 Week 8, Class 3 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 9 Lab: Individual demos of working sub-modules.
Java Thread Programming
Concurrency 2 CS 2110 – Spring 2016.
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Week 2, Day 1: The Factory Method Pattern
Threads and Memory Models Hal Perkins Autumn 2011
Week 6, Class 2: Observer Pattern
Threads and Memory Models Hal Perkins Autumn 2009
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Polling vs. Interrupts CS2852 4/9/2019
Polling vs. Interrupts CS2852 4/21/2019
Slide design: Dr. Mark L. Hornick
Week 8, Class 3: Model-View-Controller
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Problems with Locks Andrew Whitaker CSE451.
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Slide design: Dr. Mark L. Hornick
More concurrency issues
Presentation transcript:

Today Quiz not yet graded (Sorry!) More on Multithreading Happens-Before in Java Other langauges with Happens-Before Happens-Before in C++ SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 9, Class 2

Volatile designs.deviantart.com/art/Warning- Extremely-Volatile designs.deviantart.com/art/Warning- Extremely-Volatile ug-profiles/volatile ug-profiles/volatile volatile/ volatile/ disasters.blogspot.com/2010/11/volcano- death-toll-rises-past-320.html disasters.blogspot.com/2010/11/volcano- death-toll-rises-past-320.html losive-anger/ losive-anger/ SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 2

Volatile readily vaporizable at a relatively low temperature flying or having the power to fly lighthearted, lively tending to erupt into violence : explosive unable to hold the attention fixed because of an inherent lightness or fickleness of disposition difficult to capture or hold permanently volatile/ SE-2811 Dr.Yoder 3

Based on these definitions, which do you think is a closer fit for volatile? A variable which is cached – at any time, value could be incorrect because other threads change it. A variable which is not cached. Must always go to main memory to read value, because other threads may change it at any time. Note: I am NOT asking which is volatile in Java or other languages. SE-2811 Dr.Yoder 4

Volatile (in Java) A variable which is not cached. Must always go to main memory to read or write the value SE-2811 Dr.Yoder 5

Sequential Consistency A program is sequentially consistent if every read is immediately visible on every other thread, in the program order. The “hop-back-and-forth between threads” model If language were sequentially consistent by default, could not reorder instructions or use cache (Research area: Or would it?) ml/jls-17.html#jls-17.4 SE-2811 Dr.Yoder 6

Some definitions “Two accesses to (reads of or writes to) the same variable are said to be conflicting if at least one of the accesses is a write.” (§17.4.1)§ “When a program contains two conflicting accesses that are not ordered by a happens- before relationship, it is said to contain a data race.” (§17.4.5)§ SE-2811 Dr.Yoder 7

Data-race free programs (updated) If a program has no data races, then we can treat that program as if it behaved according to our simple “switch-back-and-forth- between-threads” model – it is sequentially consistent This is nice, but there can still be problems E.g. single-locked singleton It doesn’t guarantee that operations will happen or fail as a unit - atomically SE-2811 Dr.Yoder 8

A set of operations that happen all at once; they cannot be interrupted if(theInstance == null) { theInstance = new MySingleton(); } Atomic (review?) SE-2811 Dr.Yoder 9 Example: Should be atomic

Volatile caveat (review) Although writes to references are protected by volatile, writes to objects are not. If you want a volatile object, you have to declare all its fields volatile (not recommended) Even then… You can’t do this for objects in the standard library Your class may still have parts that need to be atomic but are not If you are calling a method that is not designed to be used without synchronization, you should synchronize around it. SE-2811 Dr.Yoder 10

Ex. Happens-before explanation if(loggers.get(path)==null){ synchronized (loggers){ if(loggers.get(path) == null){ Logger logger = new EventLogger(path); loggers.put(path, logger); } SE-2811 Dr.Yoder 11 Write whether this code contains any data races. Explain your answer. Assume loggers is thread safe.

An alternative: java.util.concurrent (review) Lock-free multi-threaded data structures: ConcurrentHashMap Like HashMap, only “concurrent” ConcurrentSkipListMap Like TreeMap, only “concurrent” Discussed in Dean & Dean SE1011 book recommended by a student for studying data structures SE-2811 Dr. Yoder 12

Languages using Happens- Before Java C++11 Golang LLVM (Technically not a language, but a compiler infrastructure, but it does include an intermediate representation language) LLVM intermediate representation before-relation/ SE-2811 Dr.Yoder 13

Happens-Before in C++11 Some are transitive “If we ignore consume operations and the dependency-ordered-before relation in C++11, the remaining forms of happens-before end up being transitive.” (Preshing) before-relation/ before-relation/ mory_order mory_order val_order val_order SE-2811 Dr.Yoder 14

Example #include std::atomic ptr; int data; void producer() { std::string* p = new std::string("Hello"); data = 42; ptr.store(p, std::memory_order_release); } void consumer() { std::string* p2; while (!(p2 = ptr.load(std::memory_order_acquire))) ; assert(*p2 == "Hello"); // never fires assert(data == 42); // never fires } int main() { std::thread t1(producer); std::thread t2(consumer); t1.join(); t2.join(); } SE-2811 Dr.Yoder 15

Muddiest Point Wait for the slides, or follow this link to answer both questions at once: SE-2811 Dr.Yoder 16

SE-2811 Dr. Josiah Yoder 17

SE-2811 Dr. Josiah Yoder 18

References EBB: Derek Malloy, Exploring Beaglebone, Wiley, 2015 RTS: Laplante and Ovaska, Real-Time Systems Design and Analysis by, Fourth Edition, Wiley, 2012 SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 19

Someday soon Late next week? Real-Time Operating Systems What is a RTOS? How does it relate to the rest? OS roles Interrupts and the OS Definitions, Flowchart, Timing diagram Detailed steps Scheduling Task states & pre-runtime vs runtime SE-2811 Dr.Yoder 20

Task States Wiki:Process (computing) See also Laplante and Ovaske 4E p. 97 SE-2811 Dr.Yoder 21

Some happens-before relationships Every action in a thread Exit synch. section Write to volatile field Any action avase/8/docs/api/java/ut il/concurrent/package- summary.html#Memory Visibility actions later in program order in same thread Enter synch. section locked on same object (later in time) Read of volatile field (later in time) Any action which happens before an action which … happens before this action (chaining) SE-2811 Dr. Yoder 22