Skip to Content
Programming with Qt, 2nd Edition
book

Programming with Qt, 2nd Edition

by Matthias Kalle Dalheimer
January 2002
Beginner to intermediate
522 pages
14h 36m
English
O'Reilly Media, Inc.
Content preview from Programming with Qt, 2nd Edition

Chapter 20. Multithreading

So far, whatever we did in our Qt programs, only one thing happened at a time. Of course, we could run several instances of a program, but that was a different issue; the two processes were completely independent of each other. In this chapter, we will look at multithreading, which lets you have several threads of control in one process at the same time. Of course, unless you have a multiprocessor machine, only one of these threads can be executed at a time. To the observer (and that includes you, the developer), however, it looks like all (or at least some) threads are run at the same time.

Since threads run in the same process, all threads have access to the process’s memory, including all variables. This situation brings an inherent danger: one thread might make a change to a variable and before it can use that change, another thread could overwrite it again. This scenario might bring unexpected results for the first thread. The only data that is safe is data that is on the stack because each thread has a stack of its own. Thus, local variables cannot be shared between two threads, and each thread is free to access its own local variable at its leisure without needing to pay attention to what other threads do.

Multithreading looks deceptively simple, but these synchronization problems make it an extremely difficult task. Sure, there are tools and techniques for solving these problems, but it is still very difficult, and synchronization problems are ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ GUI Programming with Qt 4

C++ GUI Programming with Qt 4

Jasmin Blanchette, Mark Summerfield
C++ GUI Programming with Qt 4

C++ GUI Programming with Qt 4

Jasmin Blanchette, Mark Summerfield

Publisher Resources

ISBN: 0596000642Supplemental ContentErrata Page