Open Bug 1713979 Opened 4 years ago

Should NS_IsMainThread() return false or true, or crash, before/after the end of main()?

Categories

(Core :: XPCOM, task)

task

Tracking

()

People

(Reporter: mozbugz, Unassigned)

Details

As seen in some crash reports like https://crash-stats.mozilla.org/report/index/dcb7a786-a728-43be-9e3f-7f2e20210601 , NS_IsMainThread() returns false during the post-main() processing (e.g., when destroying static objects).

In one sense, it's helpful in catching some unexpected behavior.

But conceptually, I'm wondering if what happens after main() ends is still on "the main thread"? I believe it's the same thread of code that has common root functions in the initial thread of the process.

Is NS_IsMainThread() just exposing an arbitrary way in which its implementation through MOZ_THREAD_LOCAL works? The crash reports I'm seeing only happen on Windows, which may show a discrepancy between platforms.

So I'm not too sure what it should do (false, true, or always crash?), but I think we should at least discuss it, and maybe document it where it's declared.

And to be complete, we may want to also consider what happens before main() starts! (e.g., when global static objects get initialized.)

You need to log in before you can comment on or make changes to this bug.