{"id":2210,"date":"2011-01-18T14:03:37","date_gmt":"2011-01-18T22:03:37","guid":{"rendered":"http:\/\/blog.mozilla.org\/addons\/?p=2210"},"modified":"2011-01-18T14:03:37","modified_gmt":"2011-01-18T22:03:37","slug":"threads-n-workers-in-firefox-4","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/","title":{"rendered":"Threads and Workers for Add-ons in Firefox 4"},"content":{"rendered":"<p>The upcoming Firefox 4 includes a ton of significant changes, many of which have a <a href=\"http:\/\/blog.mozilla.org\/addons\/2010\/11\/11\/making-add-on-compatible-firefox-4\/\">direct effect on add-ons<\/a>. The majority of these changes are just new and different ways of doing things. Unfortunately, there are a couple of changes that offer no alternative and add-on authors will just need to cope with them. The stability changes that were introduced in the threading model for Firefox 4 are an example of this.<\/p>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en\/The_Thread_Manager\">Thread Manager<\/a> was introduced in Firefox 3, and it appeared to work OK all the way up to recent Firefox 4 betas. This object allowed add-ons to run JS code on separate threads, pass objects to these threads and even access XPCOM objects within them.<\/p>\n<p>It turns out that this was detrimental to the stability of the browser, and passing JS objects between threads would cause Firefox to randomly crash. When the cause of these crashes was found, the <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=608142\">bug was fixed<\/a>, irreversibly rendering the Thread Manager object fairly useless for add-ons.<\/p>\n<p>Since a number of add-ons have been relying on the Thread Manager for some time, this change was quickly picked up by some authors and a discussion about it began shortly thereafter. The conclusion of this discussion is that there was no way the Thread Manager could allow passing JS objects again, and that the appropriate alternative was to use <a href=\"https:\/\/developer.mozilla.org\/en\/DOM\/ChromeWorker\">ChromeWorkers<\/a>. At the moment of this discussion, a ChromeWorker was just the same as a <a href=\"https:\/\/developer.mozilla.org\/En\/DOM\/Worker\">Worker<\/a>, with the only difference of being able to use js-ctypes to connect to compiled libraries. This wasn&#8217;t enough for add-ons, though, so the introduction of XPCOM in ChromeWorkers began.<\/p>\n<p>This leads us to the current state of affairs: if you want to run code on a separate thread, our best recommendation is to use <a href=\"https:\/\/developer.mozilla.org\/en\/DOM\/ChromeWorker\">ChromeWorkers<\/a>. They can now access <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=618484\">XPCOM objects<\/a>, as explained in the documentation, limited to components that have been marked as thread-safe. Because of this only a few components are currently accessible, and trying to use a non-thread-safe component will throw an exception right away.<\/p>\n<p>This is as good as things will get in the Firefox 4 timeline, unfortunately. I&#8217;m already talking with the platform team about ways to make more XPCOM components thread-safe and therefore useable from ChromeWorkers. I&#8217;ve been looking at Thread Manager usage in add-ons listed on AMO, so I have a good idea of how add-ons were using these interfaces. The most frequent uses, like file system I\/O will take precedence, and hopefully they will be included in whatever Firefox release comes after 4.<\/p>\n<p>If you have an add-on that is affected by this change, I&#8217;m interested in knowing how you are\/were using threads in your add-on. This can have an effect in future Firefox development, so please leave a comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The upcoming Firefox 4 includes a ton of significant changes, many of which have a direct effect on add-ons. The majority of these changes are just new and different ways &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/\">Read more<\/a><\/p>\n","protected":false},"author":173,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[388,44,295],"tags":[805,278877,278873,579,888],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Threads and Workers for Add-ons in Firefox 4 - Mozilla Add-ons Community Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jorge Villalobos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/\",\"name\":\"Threads and Workers for Add-ons in Firefox 4 - Mozilla Add-ons Community Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#website\"},\"datePublished\":\"2011-01-18T22:03:37+00:00\",\"dateModified\":\"2011-01-18T22:03:37+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/a098261b4b5510d408ff31f492606925\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/addons\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Threads and Workers for Add-ons in Firefox 4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/\",\"name\":\"Mozilla Add-ons Community Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/addons\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/a098261b4b5510d408ff31f492606925\",\"name\":\"Jorge Villalobos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6d1966118f16e4b99a6e3ad07883be33?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6d1966118f16e4b99a6e3ad07883be33?s=96&d=mm&r=g\",\"caption\":\"Jorge Villalobos\"},\"description\":\"Jorge is the Product Manager for addons.mozilla.org\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/author\/jvillalobosmozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Threads and Workers for Add-ons in Firefox 4 - Mozilla Add-ons Community Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/","twitter_misc":{"Written by":"Jorge Villalobos","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/","url":"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/","name":"Threads and Workers for Add-ons in Firefox 4 - Mozilla Add-ons Community Blog","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/addons\/#website"},"datePublished":"2011-01-18T22:03:37+00:00","dateModified":"2011-01-18T22:03:37+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/a098261b4b5510d408ff31f492606925"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/addons\/2011\/01\/18\/threads-n-workers-in-firefox-4\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/addons\/"},{"@type":"ListItem","position":2,"name":"Threads and Workers for Add-ons in Firefox 4"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/addons\/#website","url":"https:\/\/blog.mozilla.org\/addons\/","name":"Mozilla Add-ons Community Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/addons\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/a098261b4b5510d408ff31f492606925","name":"Jorge Villalobos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6d1966118f16e4b99a6e3ad07883be33?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6d1966118f16e4b99a6e3ad07883be33?s=96&d=mm&r=g","caption":"Jorge Villalobos"},"description":"Jorge is the Product Manager for addons.mozilla.org","url":"https:\/\/blog.mozilla.org\/addons\/author\/jvillalobosmozilla-com\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts\/2210"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/users\/173"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/comments?post=2210"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts\/2210\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/media?parent=2210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/categories?post=2210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/tags?post=2210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}