230 likes | 341 Views
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 I nterrupt Signal.
E N D
2.2 Sounds good? • Hardware Interrupt • Signal
2.3 Reentrancy Lock the Mutex Call increment() Interrupt Some Operations Unable to Lock Unlock the Mutex
3.3 How Do They Do it? • Hardware Support for Atomic Operations (adding, incrementing, subtracting, etc.) • Support for CAS (hardware / software)
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