Does anybody know of a fully thread-safe shared_ptr implementation? E.g. boost implementation of shared_ptr is thread-safe for the targets (refcounting
I don't know of such a smart pointer implementation, though I have to ask: how could this behaviour be useful? The only scenarios I can think of where you would find simultaneous pointer updates are race conditions (i.e. bugs).
This is not a criticism -- there may well be a legitimate use case, I just can't think of it. Please let me know!
Re: EDIT2 Thanks for providing a couple of scenarios. It does sound like atomic pointer writes would be useful in those situations. (One little thing: for the second example, when you wrote "If it's not NULL, it prevents the processor from being destroyed by assigning it to its own shared-ptr", I hope you meant that you assign the global shared pointer to the local shared pointer first then check whether the local shared pointer is NULL -- the way you described it is prone to a race condition where the global shared pointer becomes NULL after you test for it and before you assign it to the local one.)