hxy debugging made by 14302010050. contents 目录 history of java mt sequential & parallel...
TRANSCRIPT
![Page 1: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/1.jpg)
HXY
Debugging
Made by 14302010050
![Page 2: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/2.jpg)
Contents目录
History of Java MT
Sequential & Parallel
Different types of bugs
Debugging skills
![Page 3: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/3.jpg)
Part One
History of Java MT01
![Page 4: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/4.jpg)
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
![Page 5: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/5.jpg)
Part Two
Sequential & Parallel02
![Page 6: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/6.jpg)
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 model01
02
03
![Page 7: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/7.jpg)
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.
![Page 8: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/8.jpg)
Part Three
Different types of bugs03
![Page 9: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/9.jpg)
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
![Page 10: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/10.jpg)
Part Four
Debugging skills04
![Page 11: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/11.jpg)
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
![Page 12: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/12.jpg)
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
![Page 13: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/13.jpg)
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
![Page 14: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/14.jpg)
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
![Page 15: HXY Debugging Made by 14302010050. Contents 目录 History of Java MT Sequential & Parallel Different types of bugs Debugging skills](https://reader036.vdocuments.site/reader036/viewer/2022082400/5697c0051a28abf838cc503e/html5/thumbnails/15.jpg)
HXY
Thank You
Made by 14302010050