17.4.  Review Questions

[ fromfile: concurrency-questions.xml id: concurrency-questions ]

  1. List and explain at least two mechanisms by which a parent process communicates information to its child process.

     

    1. Command-line arguments

    2. standard input and output streams

    3. environment variables

  2. List and explain at least two mechanisms by which threads synchronize with each other.

     

    1. locks

    2. wait conditions

    3. mutexes

    4. semaphores

  3. In what situations can a QTimer be used instead of a QThread? Why would one want to do that?

      A QTimer is useful if the simultaneous task that needs to be performed can be implemented as an incremental algorithm that requires repeated calls to a function that does not run for a long period of time. In this situation, we can avoid the use of threads (which sometimes have problems accessing QObjects/QWidgets from other threads).

  4. What does it mean for an function to be thread-safe?

     A thread-safe function is one that can be called concurrently by multiple threads and is guaranteed to serialize access to shared data, perhaps through the use of a mutex or lock.

  5. Which class can be used in non-GUI threads? QImage or QPixmap?

      QImage can be used in other threads. QPixmap is considered a "gui" class and should only be used in the main GUI thread.

  6. What does it mean for a function to be reentrant?

      Multiple threads can call a reentrant function safely, and they do not need to access the same data, so they do not block each other during the calls.

  7. How do you tell a non-GUI thread to enter into an event loop?

      QThread::exec()

  8. Without using extra threads, how can you keep the GUI responsive while still performing a long-running loop?

      qApp->processEvents()