I googled this question but, although there are many discussions about it, I didn't find a clear answer.
Can I assume the following piece of code to be thread safe?

shared_ptr<T> p1(new XXX); //Main thread
weak_ptr<T> wp(sp); //Main thread

//Then I run two threads: A and B
p1.reset(); // thread A
shared_ptr<T> p2 = wp.lock(); // thread B
In other words, is lock method atomic in respect to deference of the shared point?

--
korg Firma

KORG ITALY SPA

Via Cagiata, 85 – 60027 Osimo (AN) - ITALY

Ph.   +39 071 727161 -  Fax   +39 071 7231228

P.IVA e Cod. fiscale IT01460580424

Soggetta al controllo della Società KORG Inc. - Giappone

Reg. Imprese di n. 212056/1996 del 23/12/96

REA di Ancona al n. 133105 del 06/12/96

Capitale sociale Euro 814.253,16  i.v.

 

 

 

Ai sensi del D.Lgs. 30 giugno 2003, n. 196, “Codice in materia di protezione dei dati personali” si precisa che le informazioni contenute nel messaggio sono riservate e destinate esclusivamente alla persona od organizzazione sopra indicata. A chi legge il presente avviso - se non è l'effettivo destinatario, o un dipendente, o la persona responsabile della consegna del messaggio - si notifica che sono proibite copie, distribuzione o divulgazione di quanto in esso contenuto (C.P. 616). Se questo messaggio Vi è pervenuto per errore, Vi preghiamo di informarci immediatamente, di non leggerlo e di distruggerlo. Grazie.

 

According to Legislative Decree n. 196 of 30 June 2003 about “Personal Data Protection Code” we point out that the information contained in this message may be privileged and confidential and is intended only for the use of the individual entity named above. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this message is strictly prohibited. If you have received this message in error, please notify us immediately and destroy the original message. Thank you.