Using web workers

  • Revision slug: Talk:DOM/Using_web_workers
  • Revision title: Using web workers
  • Revision id: 19269
  • Created:
  • Creator: Wjjohnst
  • Is current revision? No
  • Comment no wording changes

Revision Content

Workers in extensions - Threadsafety

Workers in extensions don't have access to the the Components object from their thread making it nearly impossible to create XPCOM objects in a worker. Objects passed to workers will always be sent as JSON making it impossible to inject one into the worker thread. As such I can't think of any special reason you'd have to worry about threadsafety in extensions differently than normal web pages. If someone does need to use XPCOM objects in threaded code they can use the Thread Manager instead, and will need to look into thread-safety for the created objects.

I'm certainly not an expert on workers, threads or on Mozilla's use of them though, so I'm refraining from changing this article. Maybe there is some extra worry about threads in extensions, or some way to create Components/Services that I'm not aware of.

Revision Source

<h3>Workers in extensions - Threadsafety</h3>
<p>Workers in extensions don't have access to the the <a class="internal" href="/En/Components%20object" title="En/Components object">Components object</a> from their thread making it nearly impossible to create <a class="internal" href="/En/XPCOM" title="En/XPCOM">XPCOM</a> objects in a worker. Objects passed to workers will always be sent as <a class="internal" href="/En/JSON" title="En/JSON">JSON</a> making it impossible to inject one into the worker thread. As such I can't think of any special reason you'd have to worry about threadsafety in extensions differently than normal web pages. If someone does need to use <a class="internal" href="/En/XPCOM" title="En/XPCOM">XPCOM</a> objects in threaded code they can use <a class="internal" href="/En/The%20Thread%20Manager" title="En/The Thread Manager">the Thread Manager</a> instead, and will need to look into thread-safety for the created objects.</p>
<p>I'm certainly not an expert on workers, threads or on Mozilla's use of them though, so I'm refraining from changing this article. Maybe there is some extra worry about threads in extensions, or some way to create Components/Services that I'm not aware of.</p>
Revert to this revision