3

I am wondering the member function of shared_ptr, weak_ptr are thread-safe or not?

For example:

Is the weak_ptr::expired an atomic operation?

Is shared_ptr<CAT> spc = aother_shared_ptr_obj; an atomic operation?

Thanks.

shauryachats
  • 9,975
  • 4
  • 35
  • 48
camino
  • 10,085
  • 20
  • 64
  • 115
  • 2
    see e.g http://stackoverflow.com/questions/14482830/stdshared-ptr-thread-safety – Cheers and hth. - Alf Mar 14 '15 at 03:32
  • I would assume that `expired` would be atomic... and *useless*. The fact that the `weak_ptr` is not expired when you call that function does not mean that it won't be expired by the time you try to do anything with it, even if it is immediately. – David Rodríguez - dribeas Mar 14 '15 at 03:48
  • 1
    @David: Think the other direction: you call expired not because you want to do something while the object is *alive*, but because you want to do something when the object is *dead*. –  Mar 14 '15 at 07:32

0 Answers0