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
23
Embed
Today Return Quiz First release of final project template Multithreading Options Qt socket buffers between threads Tomorrow: Quiz Interthread communication.
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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Today Return Quiz First release of final project template Multithreading Options
Qt socket buffers between threads Tomorrow: Quiz
Interthread communication in Qt
SE-2811Slide design: Dr. Mark L. Hornick
Content: Dr. HornickErrors: Dr. Yoder
1
SE3910Week 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] http://stackoverflow.com/questions/4140189/qthreads-vs-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.http://stackoverflow.com/questions/5269535/java-threads-vs-pthreads
SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick
Wiki:Process (computing)See also Laplante and Ovaske 4E p. 97SE-2811
Dr.Yoder 4
Threading – pthreads (review) Java Pthreadsjava.lang.Thread #include <pthread.h>No external jar needed link with -pthreadThread t = new Thread(r)t.start();
Ex: Edit to include notify/wait to interleave these threads.Consider this code-snippetQueue q = ……synchronized(q) { while(true) { img = getImage(); q.offer(img); }}
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.”https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/I have successfully used this approach.
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.
Qt::DirectConnection 1 The slot is invoked immediately when the signal is emitted. The
slot is executed in the signalling thread.
Qt::QueuedConnection 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::BlockingQueuedConnection 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::UniqueConnection 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.