OK, here's a more focused question - let's imagine that one is implementing SharedWorkers in a new browser. One seemingly reasonable way to proceed would be to have a Worker stay alive as long as there are *any* reachable entangled ports between any window and that worker. Does this cause some kind of problem that's addressed by the more complex behavior described in the spec?<div>
<br></div><div>The "any reachable port" implementation seems like it's more along the lines of what people would expect, and doesn't require a new concept to be tracked (the port's original creator). I just have the nagging feeling that I'm not properly translating from "spec language" into actual behavior, and perhaps the intended behavior is not as complex as the spec implies.</div>
<div><br></div><div>-atw<br><br><div class="gmail_quote">On Fri, Apr 10, 2009 at 6:32 PM, Drew Wilson <span dir="ltr"><<a href="mailto:atwilson@google.com">atwilson@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<div><br></div><div>A couple of quick questions about the lifecycle of workers - specifically I'm trying to grok the body of text at section 4.5 of the Web Workers spec. It seems like it's saying that if I create a shared worker, then hand off its port to another window, that shared worker will be orphaned once the original window is closed.</div>
<div><br></div><div>It seems like instead of just using the normal message port reachability algorithm (once a worker's message ports are no longer reachable, it is considered orphaned) we instead have to track the original allocator of all ports, and only count a worker as reachable if the window that allocated the original port is still active.</div>
<div><br></div><div>"[a worker is permissible if] <span style="font-family:Helvetica;font-size:16px">at some point past or present a <span style="font:13.0px Courier;color:#ff2e00">MessagePort</span> owned by the worker was entangled with a <span style="font:13.0px Courier;color:#ff2e00">MessagePort</span> <i>p</i> whose owner is a <span style="font:13.0px Courier;color:#ff2e00">Window</span> object whose active document is the <span style="font:13.0px Courier;color:#ff2e00">Document</span> that was that browsing context's active document when <i>p</i> was created, and that <span style="font:13.0px Courier;color:#ff2e00">Document</span> is fully active"</span></div>
<div><br></div><div>Am I reading this correctly? It just seems wonky that if I create a shared worker from window A, hand the port off to window B, then close window A, that worker is now orphaned despite being reachable from window B. But if I do the same thing, but before window A closes, window B creates a new port and sends it to the worker via the port that window A gave it, the worker won't be orphaned when window A closes.</div>
<div><br></div><div>What's the intent here?</div><div><br></div><div>Also, one other thing: I was previously under the impression that SharedWorkers had a different lifecycle from dedicated Workers - SharedWorkers would not exit as long as there were any windows open to that domain. In retrospect, I'm pretty sure I just made that up - SharedWorkers and dedicated Workers have identical lifecycles, correct?</div>
<div><br></div><div>-atw</div><div><br></div>
</blockquote></div><br></div>