Programmation Objet en JAVA Cours 8 Thread, Multi-thread, synchronisation,...
The ABCs of thread safety
-
Upload
ezekiel-acevedo -
Category
Documents
-
view
24 -
download
3
description
Transcript of The ABCs of thread safety
THE ABCS OF THREAD SAFETY郑宜霖
0 THREAD
0.0 WHAT ARE THREADS
0.1 WHY THREADS
1 THREAD “UNSAFETY”
1.0 RACE CONDITION
1.1 CASE I: READ-INCREASE-WRITE
1.2 CASE II: REMOVING A NODE
2 MUTEX
2.0 MUTUAL EXCLUSION
2.1 INCREMENT-MUTEX
2.2 SOUNDS GOOD?
•Hardware Interrupt
•Signal
2.3 REENTRANCY
Lock the Mutex
Interrupt Call increment()
Unable to LockSome Operations
Unlock the Mutex
3 ATOMIC OPERATION
3.0 ATOMIC OPERATIONS
3.1 INCREMENT-ATOMIC
3.2 STD::ATOMIC
3.3 HOW DO THEY DO IT?
• Hardware Support for Atomic Operations (adding, incrementing, subtracting, etc.)
• Support for CAS (hardware / software)
3.4 COMPARE-AND-SWAP
3.5 INCREMENT-CAS
3.6 WHAT’S MORE
•Only CAS with 1, 2 ,4 ,8 Bytes
•How to implement an atomic class?
REFERENCES
• GStreamer Application Development Manual
• Wikipedia
• Cppreference
• GCC Wiki
THANKS