Reputation: 11
I am new to develop Firefox extension with XPCOM. Currently I am using a background thread to do some work in XPCOM and need to pass a pointer of one XPCOM interface (eg nsIDomwindow) from main thread to that thread. But if use the pointer as the parameter in windows API fundtion Createthread and use it then, that will cause Firefox crash.
How to solve this issue? Is there any similar way to use CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream in MS com? Does the XPCOM only support single thread?
Look forward all your advice and sample code! Thanks in advance!
Upvotes: 1
Views: 119
Reputation: 57651
Many XPCOM objects aren't thread-safe, in particular any DOM objects can only be accessed from the main thread. To check whether an object is thread-safe you have to QueryInterface
it to nsIClassInfo and check whether nsIClassInfo.flags
contains nsIClassInfo.THREADSAFE
flag. If it is then you can simply pass the interface pointer between threads.
Upvotes: 1