18 Aug
2005
18 Aug
'05
12:35 p.m.
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.