[webkit-changes] [20310] trunk

Geoffrey Garen ggaren at apple.com
Sun Mar 18 23:06:18 PDT 2007


I think this turned into a really cool solution.

+CommonIdentifiers* CommonIdentifiers::shared()
+{
+    static CommonIdentifiers* sharedInstance;
+    if (!sharedInstance) {
+        JSLock lock;
+        sharedInstance = new CommonIdentifiers;
+    }
+    return sharedInstance;
+}

This is "double-checked locking." Technically, it isn't thread-safe.  
(The main reason is that instructions can execute out of order, so  
sharedInstance can become non-NULL before it is completely  
initialized.) I would recommend asserting that the caller holds the  
JSLock, instead. I think that's already true in your code, so it  
shouldn't be a problem.

Geoff



More information about the webkit-changes mailing list