- From: Jonas Sicking <jonas@sicking.cc>
- Date: Thu, 5 Mar 2009 17:55:23 -0800
On Thu, Mar 5, 2009 at 5:44 PM, Drew Wilson <atwilson at google.com> wrote: > So an asynchronous cookie setting API would look like: > > setCookie(cookieStr, callback) > > ...where the callback is invoked once the cookie has been set? > > I guess I don't yet entirely understand the implementation details - it > sounds like there are problems accessing any shared state between workers > and window context? The problem is with code like the following: if (sharedState < 0) { sharedState = sharedState * -1; } You would expect sharedState to always be non-negative at the end of such a program, right? Well, that might not be the case since script running in parallel in the main window might have changed the value of sharedState from -5 to 10 between the if-statement and the assignment, resulting in sharedState being -10 at the end. This is why workers use a shared-nothing message passing interface between workers and windows. This is something that simply can't be fixed in the implementation, but something that scripts would have to deal with themselves. It's unlikely that web developers would do this correctly since working with threads is *very hard* and something that even seasoned developers often get wrong. / Jonas
Received on Thursday, 5 March 2009 17:55:23 UTC