Reviewers: Hannes Payer,

Message:
Hi Hannes,
Here is one of the issues to address. PTAL, thx,
--Michael

ps - I think I see a comment to be removed.

Description:
LazyInstance should be thread safe by default.

The only ways we use this class require it, as multiple isolates can race
to initialize data structures. This showed up as intermittant failures on
nosnap build bots.

[email protected]

Please review this at https://codereview.chromium.org/238973004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+7, -5 lines):
  M src/lazy-instance.h


Index: src/lazy-instance.h
diff --git a/src/lazy-instance.h b/src/lazy-instance.h
index fc03f4d126025070fb490073ff9984446d68af3c..86473fd63ae7c90c6c1952f3a31ed8d8df7d9496 100644
--- a/src/lazy-instance.h
+++ b/src/lazy-instance.h
@@ -66,8 +66,8 @@
 //      LAZY_INSTANCE_INITIALIZER;
 //
 // WARNINGS:
-// - This implementation of LazyInstance is NOT THREAD-SAFE by default. See
-//   ThreadSafeInitOnceTrait declared below for that.
+// - This implementation of LazyInstance IS THREAD-SAFE by default. See
+//   SingleThreadInitOnceTrait if you don't care about thread safety.
// - Lazy initialization comes with a cost. Make sure that you don't use it on
 //   critical path. Consider adding your initialization code to a function
 //   which is explicitly called once.
@@ -174,6 +174,8 @@ struct ThreadSafeInitOnceTrait {


 // Initialization trait for users who don't care about thread-safety.
+//
+// Thank you for making this the default, Satan.
 struct SingleThreadInitOnceTrait {
   template <typename Function, typename Storage>
   static void Init(OnceType* once, Function function, Storage storage) {
@@ -227,7 +229,7 @@ struct LazyInstanceImpl {

 template <typename T,
           typename CreateTrait = DefaultConstructTrait<T>,
-          typename InitOnceTrait = SingleThreadInitOnceTrait,
+          typename InitOnceTrait = ThreadSafeInitOnceTrait,
           typename DestroyTrait = LeakyInstanceTrait<T> >
 struct LazyStaticInstance {
   typedef LazyInstanceImpl<T, StaticallyAllocatedInstanceTrait<T>,
@@ -237,7 +239,7 @@ struct LazyStaticInstance {

 template <typename T,
           typename CreateTrait = DefaultConstructTrait<T>,
-          typename InitOnceTrait = SingleThreadInitOnceTrait,
+          typename InitOnceTrait = ThreadSafeInitOnceTrait,
           typename DestroyTrait = LeakyInstanceTrait<T> >
 struct LazyInstance {
   // A LazyInstance is a LazyStaticInstance.
@@ -248,7 +250,7 @@ struct LazyInstance {

 template <typename T,
           typename CreateTrait = DefaultCreateTrait<T>,
-          typename InitOnceTrait = SingleThreadInitOnceTrait,
+          typename InitOnceTrait = ThreadSafeInitOnceTrait,
           typename DestroyTrait = LeakyInstanceTrait<T> >
 struct LazyDynamicInstance {
   typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>,


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to