100 likes | 255 Views
Debugging Threaded Applications. By Andrew Binstock http://software.intel.com/sites/billboard/archive/debugging-threaded-applications.php CMPS 5433- Parallel Processing Halverson. Why?. PP difficult due to complexity of threads Concurrent threads = Speedup Correct design of threads
E N D
Debugging Threaded Applications By Andrew Binstock http://software.intel.com/sites/billboard/archive/debugging-threaded-applications.php CMPS 5433- Parallel Processing Halverson
Why? • PP difficult due to complexity of threads • Concurrent threads = Speedup • Correct design of threads • Orderly • Well designed • Predictable • Interference among threads causes problems
Threading Bugs • When 2 threads interact • One sends a result to another • When 2 threads share a common data variable • Updating a shared array
Common Violations TRY TO AVOID • Data Races • Deadlocks • Live Locks
Data Race • Occurs: When 2 threads share variable but don’t guard against simultaneous access • E.G. Selecting seat on an airplane • Recognize: Inconsistent results using same data • Cause: No mutual exclusion on shared variable • Prevention: Use mutual exclusion (lock)
Deadlock • Occurs: Two or more threads blocked as each waits on a lock held by the other • E.G. Combat game – clearing street & removing snipers • Recognize: Threads don’t advance; program may freeze • Cause: Failure to identify dependence; acquiring locks in wrong order • E.G. Game record score – display & record
Deadlock (cont’d) • Avoid: • Required order of acquiring locks • Release one lock of second is not available
Live Lock • Occurs: Multiple threads do not advance though actively working • Often - Algorithm flaw, not implementation • E.G. Dining Philosophers Problem • If all 5 act synchronously • Recognize: Multiple threads and/or program freeze or infinitely loop
Live Lock (cont’d) • Hard to reproduce • May be hardware dependent • 4 cores vs. 2 cores vs. more • Prevention: Consider what happens if all threads run simultaneously
The Commercial Ad • Intel Thread Checker • Intel Thread Profiler • Intel Threading Building Blocks • Tools available to assist in • Running threads • Monitors threads • Identifies deadlock & race conditions