W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2012

Re: Synchronous postMessage for Workers?

From: Mark S. Miller <erights@google.com>
Date: Wed, 15 Feb 2012 09:37:54 -0800
Message-ID: <CABHxS9jnw_s_j4GAN5xR1Y+TkoUVu+XZJiRRxGUCj=VViwAGYQ@mail.gmail.com>
To: John J Barton <johnjbarton@johnjbarton.com>
Cc: Jonas Sicking <jonas@sicking.cc>, Glenn Maynard <glenn@zewt.org>, Ian Hickson <ian@hixie.ch>, Joshua Bell <jsbell@chromium.org>, public-webapps@w3.org, David Levin <levin@chromium.org>
On Wed, Feb 15, 2012 at 8:09 AM, John J Barton
<johnjbarton@johnjbarton.com>wrote:

> On Tue, Feb 14, 2012 at 10:39 PM, Jonas Sicking <jonas@sicking.cc> wrote:
>
[...]

> > function doStuff() {
> >  yieldUntil("x");
> > };
> >
> > now what looks like perfectly safe innocent code:
> >
> > function myFunction() {
> >  ... code here ...
> >  doStuff();
> >  ... more code ...
>
[...]

> What I am fishing for is an example [...] a function on
> another event loop access the private (closure) state of myFunction()
> in a way that the other two patterns cannot?


  function makeStatusHolder(status) {
    var listeners = [];
    return Object.freeze({
      addListener: function(newListener) { listeners.add(newListener); },
      getStatus: function() { return status; },
      setStatus: function(newStatus) {
        status = newStatus;
        listeners.forEach(function(listener) {
          listener.statusChanged(newStatus);
        });
      }
    });
  }

This pattern is unsafe of any of the listeners might call back into the
statusHolder during notification (see Fig 13.2 of my thesis). However, we
may judge a particular usage ok if we know that none of the listeners has
access, directly or indirectly, to this statusHolder itself.
Under maintenance, one of these listeners may be revised to use  yieldUntil
to wait from a result from a foreign worker that itself does not have
access to this statusHolder, thereby not violating the assumption above.
Nevertheless, if this event loop is receptive to external events while it
is waiting, this pattern becomes unsafe.

In the absence of yieldUntil, the revised listener can gain most of the
same brevity and expressivity benefits by using <
http://wiki.ecmascript.org/doku.php?id=strawman:async_functions> (Already
supported by Kris' implementation using FF generators). Though this
provides most of the benefits of yieldUntil, it does not cause these
dangers. The notification loop runs to completion in the current turn. The
listener proceeds from the yield point in a separate turn. Any
interleavings that happen during the yield also happen in separate turns
after the notification loop completes.

-- 
    Cheers,
    --MarkM
Received on Wednesday, 15 February 2012 17:38:27 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:50 GMT