Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2005-08-18 07:35:03


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net