c++ - How is atomic exchange of std:shared_ptr in libstdc++ correct -
based off of libstdc++'s implementation of atomic exchange ( https://gcc.gnu.org/ml/libstdc++/2014-10/msg00154.html ):
it looks 16 mutexes statically allocated. when atomic swap needs occur, swapping code hashes 2 pointers swapped 1 (or two) of static mutexes, locks, , swaps. if shared_ptr shared between threads , being concurrently accessed, how mutexes guarantee synchronization of concurrent access , modification? i’m guessing code assumes correct alignment of internal raw pointer, that's x86 rule, not c++ guarantee. missing makes swap atomic , correct without additional locking each read of underlying raw pointer?
the atomic_*
functions atomic respect each other. in other words, valid way concurrently access shared_ptr
being modified atomic_exchange
via atomic_load
, take same mutex (based on shared_ptr
's address) , block until atomic_exchange
completes.
Comments
Post a Comment