lundi 7 novembre 2022

Are the constructor and destructor of std::shared_ptr thread safe?

Assume we have a std::shared_ptr<int> sptr in thread1;

Thread 1 return and trigger destructor of sptr;

By the mean time thread2 called a constructor to copy sptr;

How could std::shared_ptr in multi-thread with a single atomic could guareente that this code would not crush in this race condition?

Aucun commentaire:

Enregistrer un commentaire