1 / 23

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 I nterrupt Signal.

Télécharger la présentation

The ABCs of thread safety

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The ABCs of thread safety 郑宜霖

  2. 0 thread

  3. 0.0 what are threads

  4. 0.1 why threads

  5. 1 thread “unsafety”

  6. 1.0 Race condition

  7. 1.1 CASE I: read-increase-write

  8. 1.2 CASE II: Removing a Node

  9. 2 Mutex

  10. 2.0 Mutual Exclusion

  11. 2.1 Increment-Mutex

  12. 2.2 Sounds good? • Hardware Interrupt • Signal

  13. 2.3 Reentrancy Lock the Mutex Call increment() Interrupt Some Operations Unable to Lock Unlock the Mutex

  14. 3 Atomic Operation

  15. 3.0 Atomic Operations

  16. 3.1 Increment-Atomic

  17. 3.2 std::atomic

  18. 3.3 How Do They Do it? • Hardware Support for Atomic Operations (adding, incrementing, subtracting, etc.) • Support for CAS (hardware / software)

  19. 3.4 Compare-and-swap

  20. 3.5 Increment-CAS

  21. 3.6 What’s More • Only CAS with 1, 2 ,4 ,8 Bytes • How to implement an atomic class?

  22. References • GStreamer Application Development Manual • Wikipedia • Cppreference • GCC Wiki

  23. Thanks

More Related