Download presentation
Presentation is loading. Please wait.
Published byEarl Warren Modified over 9 years ago
1
HXY Debugging Made by 14302010050
2
Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills
3
Part One History of Java MT 01
4
JDK 1.0: as a basic and essence, preemptive and cooperative multitasking History of Java MT JDK 1.2: abolish stop(), suspend(), resume() JDK 5.0 & JSR: happens- before, Lock-free(CAS) JDK 6.0 & 7.0: CyclicBarrier, spin lock, CountDownLatch
5
Part Two Sequential & Parallel 02
6
Thread Model Multi threaded apartment: There is only one block in each process, which takes control of more than one thread Single threaded apartment: Each thread is divided into a block in the process, sharing data in blocks. Single thread: One thread in one process, other process must wait until the previous ends. Thread model 01 02 03
7
Sequential & Parallel Sequential Parallel pros cons Faster only if when there is more CPUs because of higher efficiency and full use of CPU Easier to learn and has less problem, spend no time on shifting from one thread to the other. There may occur many problem when visiting public variables or methods. Some CPUs are left waiting and may cause many waste, which result in worse performance.
8
Part Three Different types of bugs 03
9
Every thread in the set are waiting for other thread’s signal to get start. Dead lock Tear apart the thread that can’t be divided by other threads. Atomicity violation The non-deterministic of the order of the executing order of threads. Ordering violation Wrongly visit the sharing memory without proper synchronization Data race Types of bug
10
Part Four Debugging skills 04
11
Cancel all threads in dead lock. Cancel some threads in the dead lock until the lock set free. Force the process to give up some resource until the dead lock is set free. Rob other process of their resource and relocate enough of it to the dead lock to set the lock free. Dead lock
12
Ordering violation Add lock to protect the atomicity of the operation, preventing it from being interrupted by other threads, guarantee the execution order to some extent. Add lock & Synchronize Checking the condition is a common solution to the problem. The critical part is to be sure that the extra conditional statement works at your will. Use condition checking
13
Data race A specific kind of race condition involves checking for a predicate Acting on the predicate, while the state can change between the time of check and the time of use. Strictly speaking, data race is just a special type of atomicity violation. Data race
14
1. lock before line 2 and unlock after line 6 2. put lines 6–8 and line 8 each into one critical region. 3. Two patches that separately fix the above two atomicity violations could deadlock with each other Debug method Atomicity violation
15
HXY Thank You Made by 14302010050
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.