This is an interesting use of shared_ptr for thread safety. Regardless of whether this is good, it depends on boost::shared_ptr . In particular, does it install some kind of fence or membranes, so that you are guaranteed that all entries in the constructor and insert functions from set are encountered before any pointer value changes.
I can find no guarantee of thread safety in general in the Boost smart pointer documentation. This surprises me, as I was sure there were some. But a quick look at the sources for 1.47.0 does not show, and that any use of boost::shared_ptr in a streaming environment will fail. (Can someone please tell me what I don't see. That boost::shared_ptr ignores streams.)
In any case, there are three possibilities: you cannot use a shared pointer in a streaming environment (which seems to be the case), a shared pointer ensures its internal consistency in a streaming environment, but does not establish order in relation to other objects, or a shared pointer sets a complete order. Only in the latter case will your code be safe as it is. In the first case, you will need some form of blocking everything, and in the second, you will need some kind of fences or membranes to ensure that the necessary notes are actually made before the publication of the new version, and that they will be visible before trying to read it.
source share