*tl;dr: To create new one-off threads using NS_NewNamedThread, you need to add them to an allowlist. Lots of cases of async work can be done on the background thread pool.*
In order to improve our overall threading picture, we're working on reducing the number of one-off threads spun up in Firefox. Part of that work is converting existing one-off threads to use the background thread instance. In light of this change, I've made an analyzer (Bug 1613440 <https://bugzilla.mozilla.org/show_bug.cgi?id=1613440>) that prevents new, unallowed instances of NS_NewNamedThread. *What does this mean? *Existing uses of NS_NewNamedThread are already allowed with a list that the static analyzer reads in. It checks for files it wants to ignore entirely and thread names that it wants to allow. If it finds a new use of NS_NewNamedThread, it will throw an error. *When does this checker run?* This is a static analyzer that runs with clang-plugin, meaning that it runs in automation and on builds with the --enable-clang-plugin flag. *Can I still use NS_NewNamedThread? *Technically yes, but you need to have your new thread's name added to the allow list. Consider if the work can be done by the background thread pool <https://searchfox.org/mozilla-central/rev/b2ccce862ef38d0d150fcac2b597f7f20091a0c7/xpcom/threads/nsThreadUtils.h#1732-1759> instead. *How do I get my new thread added to the allow list? *There are two lists - ThreadAllows.txt <https://hg.mozilla.org/integration/autoland/file/f400f164b3947b4dd54089a36ea31cca2d72805b/build/clang-plugin/ThreadAllows.txt> and ThreadFileAllows.txt <https://hg.mozilla.org/integration/autoland/file/f400f164b3947b4dd54089a36ea31cca2d72805b/build/clang-plugin/ThreadFileAllows.txt>. The difference is very simple - ThreadAllows takes *thread names* which are declared as string literals, but not all uses of NS_NewNamedThread pass a string literal. If this is your case, the analyzer might not be able to read your thread name - so you would add your *file name* to ThreadFileAllows.txt to tell the analyzer to ignore the whole file. It's better to use the thread name rather than the file name when you can, in case another named thread is added to the same file later on. *I want to use the background thread pool / convert my existing instance of NS_NewNamedThread to use the background pool. *The meta bug for this work is Bug 1595241 <https://bugzilla.mozilla.org/show_bug.cgi?id=1595241>. I always encourage new conversions to the background pool. :) For more information about the checker and how to use it, I wrote a post here <https://krispyfries.github.io/blog/2020/02/28/thread-bad-checker-good.html> that you can look at. _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform