HPlogo Debugging threads with HP Wilde Beest Debugger

Understanding complexity in thread programming

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The concurrency of threads and the parallelism of the hardware jointly contribute to the processing speed of programming applications. With threaded programs, ever on an increase in the industry, it becomes essential to understand the underlying complexity in implementing the concept. In addition, this understanding helps you interpret the results of debugging threaded programs.

The following are the most important concepts that attribute to the complexity in threaded programming:

  • Deadlock

  • Race condition

  • Priority inversion

Mutual exclusion (mutex) is a method which ensures that the threads share program resources systematically, thereby avoid unintended modification of the data in shared variables. Program segments attach locks to shared resources. This ensures mutual exclusion. Improper mutex lock-unlock in threaded applications could result in a deadlock condition which stops the program execution completely.

Race condition arises when shared data or resources are not accessed in any particular order thus resulting in inconsistent data in some instances. This possibility occurs when you write code segments without ensuring serial access to shared resources. Such threaded programs with inconsistent and random access to shared variables contribute to the complexity involved in debugging threads.

In addition, when a high-priority thread waits for a lock which a low-priority thread holds, the priority inversion here results in lesser execution efficiency.

Thread programs, prone to such complexities, are subject to conditions or events that reduce efficiency or increase the potential for errors.

Common conditions or events in thread programming

The following are the most common conditions or events in thread programming that could lead to errors:

  1. The thread attempts to acquire a non-recursive mutex that it currently holds.

  2. The thread attempts to unlock a mutex or a read-write lock that it has not acquired.

  3. The thread waits on a mutex or a read-write lock that is held by a thread with a different scheduling policy.

  4. Different threads non-concurrently wait on the same condition variable, but with different associated mutexes.

  5. The thread terminates execution without unlocking the associated mutexes or read-write locks.

  6. The thread waits on a condition variable for which the associated mutex is not locked.

  7. The thread terminates execution, and the resources associated with the thread continue to exist in the application because the thread has not been joined or detached.

  8. The thread uses more than the specified percentage of the stack allocated to the thread.

  9. The number of threads waiting on any pthread object exceeds the specified threshold number.

HP Wildebeest Debugger (WDB) offers advanced thread debugging features to support debugging of threaded applications and detection of these conditions.

© 2008 Hewlett-Packard Development Company, L.P.