Hello!
Now that Bug 1584568 <http://bugzil.la/1584568> just landed I wanted to
mention the new background thread pool for general purpose and blocking IO
runnables. Existing one-off threads, as well as new jobs that you may want
to run async in the background, can go to the new background thread pool
with NS_DispatchBackgroundTask(...)
<https://searchfox.org/mozilla-central/rev/2f09184ec781a2667feec87499d4b81b32b6c48e/xpcom/threads/nsThreadUtils.h#1710>.
If you've got something that cares about what order it runs in you would
want to use NS_CreateBackgroundTaskQueue
<https://searchfox.org/mozilla-central/rev/2f09184ec781a2667feec87499d4b81b32b6c48e/xpcom/threads/nsThreadUtils.h#1722>
instead.

In the past, we've sent a lot of general I/O jobs to the stream transport
service. For a lot of cases, it's now possible to use the dedicated
background threads instead. To access the I/O threads when dispatching to
the pool or to a background task queue, use the NS_DISPATCH_EVENT_MAY_BLOCK
<https://searchfox.org/mozilla-central/rev/923eec8d2fb8078ebc7a33a9e1ce73eac01f7446/xpcom/threads/nsIEventTarget.idl#63>
flag, to ensure that blocking I/O goes to its dedicated thread pool.

For a lot of cases, converting your existing async jobs or adding new ones
is pretty straightforward. Some examples of using background dispatch can
be found in Bug 1594858 <http://bugzil.la/1594858> for a basic background
task, Bug 1595242 <http://bugzil.la/1595242> for some background I/O, and Bug
1594814 <http://bugzil.la/1594814> for one that needs to use a background
task queue. Our tracking bug for this work is Bug 1595241
<http://bugzil.la/1595241>.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to