On Fri, Oct 30, 2009 at 1:36 AM, Robert O'Callahan <span dir="ltr"><<a href="mailto:robert@ocallahan.org">robert@ocallahan.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Fri, Oct 30, 2009 at 7:27 PM, Darin Fisher <span dir="ltr"><<a href="mailto:darin@chromium.org" target="_blank">darin@chromium.org</a>></span> wrote: <br></div><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
<div class="gmail_quote"><div>You are right that the conditions are specific, but I don't know that that is the</div><div>exhaustive list. Rather than defining unlock points, I would implement implicit</div><div>
unlocking by having any nested attempt to acquire a lock cause the existing lock</div><div>to be dropped. Nesting can happen in the cases you mention, but depending on</div><div>the UA, it may happen for other reasons too.</div>
</div></blockquote></div><div><br>What reasons?<br><br>If these reasons are situations where it's fundamentally difficult, impossible, or non-performant to follow the spec, we should change the spec. Otherwise this would just be a bug in the UA.<br>
</div></div></blockquote><div><br></div><div>My point is that it is difficult to ensure that all situations where nesting can occur are understood apriori and that the list doesn't change over time. Because we are talking about multi-threading synchronization in a very complex system, I would much prefer a more isolated and less fragile solution.</div>
<div><br></div><div>Unlock if yieldForStorageUpdates is called.</div><div>Unlock when returning from script execution.</div><div>Unlock if another attempt to lock occurs (any form of nesting).</div><div><br></div><div>In the third case, I'd probably log something to the JS console to alert developers.</div>
<div><br></div><div>I believe this simple implementation covers most of the cases enumerated in the spec, and it has the property of being easier to reason about and easier to support (more future proof).</div><div><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div>
<br></div><div class="im"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div class="gmail_quote">For example, a JS library might evolve to use flash for something small (like<div>
storage or sound) that it previously didn't use when I first developed my code.</div>
<div>Voila, now my storage lock is released out from under me.</div></div></blockquote></div><div><br>This example still sounds overly contrived to me. Nevertheless, it seems strange to say that because there might be a few unexpected race conditions, you have decided to allow a much larger set of unexpected race conditions.<br>
</div></div></blockquote><div><br></div><div>Why is it contrived? Many developers use high level toolkits to get their work done (e.g., jquery, prototype, dojo, google maps api, etc.). People are often one step removed from working directly with the web platform APIs. They have no idea what all is going on under the covers of those libraries, and that's a fine thing.</div>
<div><br></div><div>The idea of unlocking whenever there is nesting occurred to me when Jeremy and I were discussing how to implement unlocking for all of the cases enumerated in the spec. It equates to a good number of places in the code that are quite separated from one another. It seems very fragile to ensure that all of those cases continue to be hooked properly. I think it is very hard to test that we get it right now and in the future.</div>
<div><br></div><div>But, if we step back, we realize that the implicit unlocking is all about dealing with nesting of locks. So, I think it is _way_ better to just unlock the existing lock if an attempt is made to acquire a nested lock.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div>
<br></div><div class="im"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div class="gmail_quote"><div>At this point, I'm not favoring implementing the storage mutex in Chrome. I</div>
<div>don't think we will have it in our initial implementation of LocalStorage. I think</div>
<div>web developers that care will have to find another way to manage locking, like</div><div>using a Web Database transaction or coordinating with a Shared Worker.</div></div></blockquote><br></div>Have you considered just not implementing LocalStorage? If it's so difficult for authors to use correctly and to implement according to the spec, this seems like the best path to me.</div>
</blockquote><div><br></div><div>I have definitely considered it. I would of course prefer to drop LocalStorage and focus on something better. Chrome is unfortunately in a difficult spot given that everyone else has implemented LocalStorage (though not necessarily to spec).</div>
<div><br></div><div>So, we are currently on track to support this feature without locking. In the future, we might add locking. I've also considered other solutions, like copy-on-write, which could obviously lead to data loss, but at least it would ensure stability/consistency within a scripts execution. I would like it if the spec were open to such implementations.</div>
<div><br></div><div>What will you do for Gecko when it supports content processes?</div><div><br></div><div>-Darin</div></div>