<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MDC stuff and notes</title>
	<atom:link href="http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/</link>
	<description>Bits on the rampage: Eric Shepherd's blog.</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:15:55 -0500</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: sheppy</title>
		<link>http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/comment-page-1/#comment-82923</link>
		<dc:creator>sheppy</dc:creator>
		<pubDate>Mon, 12 Jan 2009 21:41:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/#comment-82923</guid>
		<description>Gc:

Since JavaScript always runs to completion and blocks the thread it&#039;s running on, there&#039;s never a race condition here.  Any message passed from one thread to another is placed in a queue to be run as soon as the target thread is no longer busy.

So in your example, if the worker tries to pass any message back to the main thread it won&#039;t be processed until the main thread has finished running its script, and that means the message handler will already have been set up.</description>
		<content:encoded><![CDATA[<p>Gc:</p>
<p>Since JavaScript always runs to completion and blocks the thread it&#8217;s running on, there&#8217;s never a race condition here.  Any message passed from one thread to another is placed in a queue to be run as soon as the target thread is no longer busy.</p>
<p>So in your example, if the worker tries to pass any message back to the main thread it won&#8217;t be processed until the main thread has finished running its script, and that means the message handler will already have been set up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sheppy</title>
		<link>http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/comment-page-1/#comment-82920</link>
		<dc:creator>sheppy</dc:creator>
		<pubDate>Sun, 11 Jan 2009 21:02:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/#comment-82920</guid>
		<description>I&#039;m taking your comment to the guys that wrote the worker code, and we&#039;ll see what they have to say.  Thanks!</description>
		<content:encoded><![CDATA[<p>I&#8217;m taking your comment to the guys that wrote the worker code, and we&#8217;ll see what they have to say.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gc</title>
		<link>http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/comment-page-1/#comment-82919</link>
		<dc:creator>Gc</dc:creator>
		<pubDate>Sat, 10 Jan 2009 15:05:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.bitstampede.com/2009/01/07/mdc-stuff-and-notes/#comment-82919</guid>
		<description>Using DOM Workers page

# var myWorker = new Worker(&#039;my_worker.js&#039;); 
# myWorker.onmessage = function(event) { 
#   print(&quot;Called back by the worker!\n&quot;); 
# };

It is unclear when the worker starts, so this looks like a bad example with a race condition.

If worker starts as soon as it is created [1], it looks like there is a race condition between the worker starting and adding the onmessage or onerror handler.  If the worker thread signals before the handler is added, then the handler won&#039;t get called.  Worse, the behavior will be intermittent, sometimes it may be called and sometimes it won&#039;t, or it may depend on the platform.

Maybe the initial handlers should be provided as parameters to the worker constructor to avoid this race condition (spec bug?).
Maybe the worker should have a separate .start() method so handlers can be initialized before it starts to avoid this race.

[1] http://www.whatwg.org/specs/web-workers/current-work/#worker2</description>
		<content:encoded><![CDATA[<p>Using DOM Workers page</p>
<p># var myWorker = new Worker(&#8216;my_worker.js&#8217;);<br />
# myWorker.onmessage = function(event) {<br />
#   print(&#8220;Called back by the worker!\n&#8221;);<br />
# };</p>
<p>It is unclear when the worker starts, so this looks like a bad example with a race condition.</p>
<p>If worker starts as soon as it is created [1], it looks like there is a race condition between the worker starting and adding the onmessage or onerror handler.  If the worker thread signals before the handler is added, then the handler won&#8217;t get called.  Worse, the behavior will be intermittent, sometimes it may be called and sometimes it won&#8217;t, or it may depend on the platform.</p>
<p>Maybe the initial handlers should be provided as parameters to the worker constructor to avoid this race condition (spec bug?).<br />
Maybe the worker should have a separate .start() method so handlers can be initialized before it starts to avoid this race.</p>
<p>[1] <a href="http://www.whatwg.org/specs/web-workers/current-work/#worker2" rel="nofollow">http://www.whatwg.org/specs/web-workers/current-work/#worker2</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

