Today Return Quiz First release of final project template Multithreading Options Qt socket buffers between threads Tomorrow: Quiz Interthread communication.

Slides:



Advertisements
Similar presentations
Multi-threaded applications SE SE-2811 Dr. Mark L. Hornick 2 What SE1011 students are told… When the main() method is called, the instructions.
Advertisements

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
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:
Today Networking in Linux/C Lab Eclipse cross-compiling Measuring latency of 100% CPU busy-wait polling Sleeping busy-wait polling Interrupt-driven response.
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
Week 5, Day 3: Observer Today Reducing coupling with the Observer The Observer pattern in Java APIs Posting events to a UI worker thread SE-2811 Slide.
SE3910 Week 2, Class 1 Today Basic Circuits Other ??? Tomorrow Lab 2, S365 (Complete prelab BEFORE) Thursday See ScheduleSchedule SE-2811 Slide design:
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
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.
Week 3, Day 1: Processes & Threads Processes Threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C.
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.
SE-3910 Real-time Systems Week 7, Class 1 – GStreamer – QT SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling, Some from.
Today Quiz Multithreading Options Qt socket buffers between threads Quiz today & Tuesday in lab SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
CS2910 Week 1, Class 2 Today Announce Prof. Michael Vieau’s S-341 6p Thurs Wk 2 Assignment for tomorrow Data Encoding, Part 1 Parsing Data Muddiest Point.
SE-3910 Real-time Systems Week 4, Class 1 – Quick-Quiz (Ungraded!) – Graded quiz tomorrow – Review coding in C – Libraries Threading Library in C Networking.
SE3910 Week 1, Class 2 Today – Introductions Safety Review Policy The course Tomorrow Lab 1, S365 (Purchase Beaglebone black kit BEFORE) Thursday Class.
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.
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.
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.
SE-3910 Real-time Systems Week 7, Class 1 – Announcement – GStreamer – Bins Boardshots – QT Swing & Qt Signals & Slots – Code – Example SE Dr. Josiah.
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 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:
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)
Week 7, Class 1: The Command Pattern (cont.) Get Ready for Poll Everywhere Labs 2 & 3 returned Lab 7 due this evening at 11pm Quiz tomorrow at start of.
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.
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.
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.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Week 8, Class 3: Model-View-Controller Final Project Worth 2 labs Cleanup of Ducks Reducing coupling Finishing FactoryMethod Cleanup of Singleton SE-2811.
SE3910 Week 6, Class 1 Week 6, Class 2 (Wednesday) Quiz Week 7, Class 2 (Wednesday) Half-Exam 2 Bring Calculator!! Qt GUI Design Analog and Digital Datarates.
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.
Slide design: Dr. Mark L. Hornick
Slide Style & Content: Dr. Schilling
Slide design: Dr. Mark L. Hornick
SE-3910 Real-time Systems Week 10, Class 3 Loop jamming
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
SE-2811 Software Component Design
Slide design: Dr. Mark L. Hornick
Week 6, Class 2: Observer Pattern
Multithreading.
Slide design: Dr. Mark L. Hornick
Polling vs. Interrupts CS2852 4/9/2019
Polling vs. Interrupts CS2852 4/21/2019
SE-1021 Software Engineering II
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-3910 Real-time Systems Week 4, Class 1 Quick-Quiz (Ungraded!)
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Presentation transcript:

Today Return Quiz First release of final project template Multithreading Options Qt socket buffers between threads Tomorrow: Quiz Interthread communication in Qt SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 8, Class 2

Options for multithreading (review) pthreads POSIX (Linux/Unix standard) threads Can use in C/C++ qthreads Qt Threads Object-Oriented Uses pthreads under the hood, when on POSIX [1] Derek Malloy’s GPIO class Uses pthreads under the hood, but is single- threaded Boost (Please discuss this with me BEFORE HAND if you want to use it.) [1] pthreads 2

I was asked this question in an interview today…. (continued) "When we create a thread with pthread_create() (POSIX Threads), the thread starts on its own. Why do we need to explicitly call start() in Java. What is the reason that Java doesnt start the thread when we create an instance of it." I was blank and interviewer was short of time and eventually he couldnt explain the reason to me. a-threads-vs-pthreads SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 3

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

Threading – pthreads (review) JavaPthreads java.lang.Thread#include No external jar neededlink with -pthread Thread t = new Thread(r) t.start(); pthread_create(t,r,sr,a) interface Runnable { void run(); } Parameter: void* (*sr) (void *) t.join()t.join();pthread_join(*t, &p) Object o;pthread_mutex_init(m,null) synchronized(o) { … } … /* Garbage coll. */ pthread_mutex_lock(…) … pthread_mutex_destroy(…) 5

Threading – pthreads (updated with links) JavaPthreads Object o; o.notify(); phread_cond_t c = PTHREAD_COND_INITIALIZER; pthread_cond_broadcast(c); o.wait();pthread_cond_wait(c,m); o.notify();phtread_cond_signal(c); o.notifyAll();phtread_cond_broadcast(c); SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 6 See Java coding example NotifyWaitExample Caveat: “POSIX threads can wait at condition variables of a greater generality than available in Java, but the corresponding queues may be leaky.”

Ex: Edit to include notify/wait to interleave these threads. Consider this code- snippet Queue q = … … synchronized(q) { while(true) { img = getImage(); q.offer(img); } // on another thread synchronized(q) { while(true) { img = q.poll(); showImage(); } SE-2811 Dr.Yoder 7

Threading – qthreads (with corrections) Javaqthreads java.lang.Thread#include No external jar needed(moc and friends take care of this) Thread t = new Thread(r) t.start(); QThread *t = new QThread; moveToThread(t); // note here interface Runnable { void run(); } QObject (e.g. QWidget (e.g. QMainWindow)) t.join(); connect the QThread::finish() signal to a slot that checks if all threads are done. Object o;QMutex synchronized(o) { … } … /* Garbage coll. */ Avoid sharing memory entirely… … see code example… ???? 8

Useful if you are into Qt slots/signals == events “A QThread should be used much like a regular thread instance: prepare an object (QObject) class with all your desired functionality in it. Then create a new QThread instance, push the QObject onto it using moveToThread(QThread*) of the QObject instance and call start() on the QThread instance. That’s all. ” -to-really-truly-use-qthreads-the-full-explanation/ I have successfully used this approach. SE-2811 Dr.Yoder 9

Qt’s connect method enum enum SE-2811 Dr.Yoder 10

Qt Connection types ConstantValueDescription Qt::AutoConnection 0 (Default) If the receiver lives inthe thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.lives in Qt::Direct Connection 1 The slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread. Qt::Queued Connection 2 The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed inhe t receiver's thread. Qt::Blocking QueuedConnection 3 Same as Qt::QueuedConnection, except that the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock. Qt::Unique Connection 0x80 This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set,QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). This flag was introduced in Qt 4.6.QObject::connect SE-2811 Dr.Yoder 11

Coding example. Exercise: Both the Java and Qt solutions will behave poorly if I start multiple threads. Predict how each solution will behave if I: Click start // what happens? (For Java? For Qt?) Click stop // what happens? (For Java? For Qt?) SE-2811 Dr.Yoder 12

A bit more on the Rate Monotonic Analysis SE-2811 Dr.Yoder 13

Possibly Fun Very simple C++ wrapper for pthreads cs345/lectures/CS345-Lecture-09.pdf cs345/lectures/CS345-Lecture-09.pdf notify/wait – example comparison with Java and pthreads Compares create for Java, pthreads, and Win32 threads adsII.pdf adsII.pdf SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 14

Certainly fun (Dr. Taylor’s Reviews) ointers ointers Function Pointers C/C++/Java Object-Oriented C SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 15

Other references s/02-14.jpg s/02-14.jpg Simple pthread chart From m0/index.jsp?topic=%2Fapis%2Fusers_75. htm 1m0/index.jsp?topic=%2Fapis%2Fusers_75. htm IBM example of using pthread_cond_init SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 16

Standards 9/xsh/pthread.h.html 9/xsh/pthread.h.html pthead.h 9/xsh/systypes.h.html 9/xsh/systypes.h.html systypes.h – for xxxx_t SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 17

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

SE-2811 Dr. Josiah Yoder 19

SE-2811 Dr. Josiah Yoder 20

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 21

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 22

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