SE 3910 Week 8 Class 1 l Today

  • Slides: 20
Download presentation
SE 3910 Week 8, Class 1 l Today l l l Return Quiz First

SE 3910 Week 8, Class 1 l Today l l l Return Quiz First true release of final project (Lab 8) Multithreading Options l Qt socket buffers between threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1

Quizzes l Today l l Various unit analyses (e. g. audio rates, video rates,

Quizzes l Today l l Various unit analyses (e. g. audio rates, video rates, Nyquist theorem) Scheduling l l Round-robin vs. Cyclic Code Scheduling Rate Monotonic Analysis Compile vs. Link errors In-lab (8 -Lab) l l Interthread communication Ask me on Monday! SE-2811 Dr. Yoder 2

Options for multithreading (review) l pthreads l l l qthreads l l POSIX (Linux/Unix

Options for multithreading (review) l pthreads l l l qthreads l l POSIX (Linux/Unix standard) threads Can use in C/C++ Qt Threads Object-Oriented Uses pthreads under the hood, when on POSIX [1] Derek Malloy’s GPIO class l Uses pthreads under the hood, but is singlethreaded 3

I was asked this question in an interview today…. (continued) "When we create a

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. http: //stackoverflow. com/questions/5269535/jav 4 SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling

Task States Wiki: Process (computing) See also Laplante and Ovaske 4 E p. 97

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

Threading – pthreads (review) Java Pthreads java. lang. Thread #include <pthread. h> No external

Threading – pthreads (review) Java Pthreads java. lang. Thread #include <pthread. h> No external jar needed link 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(); pthread_join(*t, &p) Object o; pthread_mutex_init(m, null) synchronized(o) { … } … /* Garbage coll. */ pthread_mutex_lock(…) … pthread_mutex_destroy(…) 6

Threading – pthreads (updated) Java Object o; o. notify(); pthreads phread_cond_t c = PTHREAD_COND_INITIALIZER;

Threading – pthreads (updated) Java Object o; o. notify(); pthreads 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. notify. All(); phtread_cond_broadcast(c); • Caveat: “POSIX threads can wait at condition variables of a greater generality than available in Java, but the corresponding queues may be leaky. ” http: //wimhesselink. nl/pub/whh 241 b. pdf SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 7

Threading – qthreads Java qthreads UN TE java. lang. Thread #include <QThread> No external

Threading – qthreads Java qthreads UN TE java. lang. Thread #include <QThread> No external jar needed (moc and friends take care of this) Thread t = new Thread(r) t. start(); QThread *q = new QThread; move. To. Thread(o); interface Runnable { void run(); } QObject (e. g. QWidget (e. g. QMain. Window)) 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… ST ? ? ED 8

Threading – qthreads Java qthreads java. lang. Thread #include <QThread> No external jar needed

Threading – qthreads Java qthreads java. lang. Thread #include <QThread> No external jar needed (moc and friends take care of this) Thread t = new Thread(r) t. start(); QThread *q = new QThread; move. To. Thread(o); interface Runnable { void run(); } QObject (e. g. QWidget (e. g. QMain. Window)) 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… ? ? 9

Looks useful if you are into Qt slots/signals == events “A QThread should be

Looks 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 move. To. Thread(QThread*) of the QObject instance and call start() on the QThread instance. That’s all. ” https: //mayaposch. wordpress. com/2011/11/01/how -to-really-truly-use-qthreads-the-full-explanation/ I have not used this approach. SE-2811 Dr. Yoder 10

Possibly Fun l Very simple C++ wrapper for pthreads l l notify/wait – example

Possibly Fun l Very simple C++ wrapper for pthreads l l notify/wait – example comparison with Java and pthreads l l http: //www. cs. utexas. edu/users/lavender/courses/ cs 345/lectures/CS 345 -Lecture-09. pdf http: //wimhesselink. nl/pub/whh 241 b. pdf Compares create for Java, pthreads, and Win 32 threads l http: //cs. millersville. edu/~csweb/lib/userfiles/9 Thre ads. II. pdf SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 11

Certainly fun (Dr. Taylor’s Reviews) l http: //msoe. us/taylor/tutorial/ce 2810/functionp ointers l l http:

Certainly fun (Dr. Taylor’s Reviews) l http: //msoe. us/taylor/tutorial/ce 2810/functionp ointers l l http: //msoe. us/taylor/tutorial/ce 2810/csimilar l l Function Pointers C/C++/Java http: //msoe. us/taylor/tutorial/ce 2810/ooc l Object-Oriented C SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 12

Other references l http: //granite. sru. edu/~whit/cpsc 464/Notes/fig s/02 -14. jpg l Simple pthread

Other references l http: //granite. sru. edu/~whit/cpsc 464/Notes/fig s/02 -14. jpg l Simple pthread chart l l From http: //granite. sru. edu/~whit/cpsc 464/Notes/ch 2. html https: //pic. dhe. ibm. com/infocenter/iseries/v 7 r 1 m 0/index. jsp? topic=%2 Fapis%2 Fusers_75. htm l IBM example of using pthread_cond_init SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 13

Standards l http: //pubs. opengroup. org/onlinepubs/790879 9/xsh/pthread. h. html l l pthead. h http:

Standards l http: //pubs. opengroup. org/onlinepubs/790879 9/xsh/pthread. h. html l l pthead. h http: //pubs. opengroup. org/onlinepubs/790879 9/xsh/systypes. h. html l systypes. h – for xxxx_t SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 14

Muddiest Point Wait for the slides, or follow this link to answer both questions

Muddiest Point Wait for the slides, or follow this link to answer both questions at once: l http: //bit. ly/1 Mow 5 a 3 SE-2811 Dr. Yoder 15

http: //bit. ly/1 Mow 5 a 3 SE-2811 Dr. Josiah Yoder 16

http: //bit. ly/1 Mow 5 a 3 SE-2811 Dr. Josiah Yoder 16

http: //bit. ly/1 Mow 5 a 3 SE-2811 Dr. Josiah Yoder 17

http: //bit. ly/1 Mow 5 a 3 SE-2811 Dr. Josiah Yoder 17

References EBB: Derek Malloy, Exploring Beaglebone, Wiley, 2015 RTS: Laplante and Ovaska, Real-Time Systems

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 18

Someday soon l Late next week? l Real-Time Operating Systems l l l Interrupts

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

Task States Wiki: Process (computing) See also Laplante and Ovaske 4 E p. 97

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