Thanks, that makes sense.
Ben Hutchings
James E Taylor wrote:
>I hope this isn't a stupid question, but.... > >Is the boost mutex constructor thread-safe? > > Clearly it's unsafe for multiple threads to call a constructor on the same block of memory concurrently. To answer the real question, dynamic initialisation of local static variables is generally not thread-safe.
>and my worry is that both threads could attempt to do the static initialisation of m concurrently. Is there protection against this? Is it even possible to protect against this? > >I've tried to use boost::call_once, which would give sufficient guarantees but it's quite inflexible as nothing can be passed to or from the function being called. > > I don't see that there's any other way to do this using current C++ and Boost.
Ben.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- James E Taylor james@onalog.net ___________________________________ NOCC, http://nocc.sourceforge.net