Hi,

 

I am building an installer app using a XUL view and an XPCOM object
performing the installation tasks. The XUL View needs to be responsive and
display progress information while the XPCOM object performs the
installation task. 

 

I tried a bunch of hacky javascript tricks to simulate multi-threading on
the javascript layer, none of them worked. 

 

What I am trying to do now is implement an nsIObserver interface in the
javascript that registers as an observer for a "topic" with
nsIObserverService and the XPCOM object sends notification through
notifyObserver during the installation tasks from a worker thread.

 

To verify the observer framework works, I first tried this on a
single-threaded environment and it worked fine.

 

I next created the worker thread to perform the installation tasks in the
background. The thread creation code is as follows:

 

nsCOMPtr<nsIThread> installThread =
do_CreateInstance("@mozilla.org/thread;1");
    nsCOMPtr<nsIRunnable> installRunnable =
do_QueryInterface(_installProcessor);
    installThread->Init(installRunnable, 
                        (PRUint32)0, 
                        (PRThreadPriority)nsIThread::PRIORITY_NORMAL, 
                        (PRThreadScope)nsIThread::SCOPE_GLOBAL, 
                        (PRThreadState)nsIThread::STATE_JOINABLE);    
    installThread->Join();

 

I got an exception stack from the notifyObserver call from the worker
thread. I am assuming this is because I need to send the observer
notifications from the UI/Main thread. 

 

Question1: How do I get the Main thread from the worker thread ?

 

Even after commenting out the notifyObserver calls, the XUL UI is still not
responsive. I see the following assertions on the console:

 

###!!! ASSERTION: nsSupportsCStringImpl not thread-safe:
'_mOwningThread.GetThread() == PR_GetCurrentThread()', file
/opt/spikesetup/src/mozilla/xpcom/ds/nsSupportsPrimitives.cpp, line 111
Break: at file
/opt/spikesetup/src/mozilla/xpcom/ds/nsSupportsPrimitives.cpp, line 111

 

Question 2: Is this assertion/break causing the UI not to be responsive ? I
would assume that the method call to the XPCOM object would have returned
control to the XUL view after creating the thread and the XUL view would
process redraw messages. 

 

Question 3: Are there other ways that are recommended for performing long
running tasks in a XPCOM object and send notifications to the XUL/Javascript
?

 

Thanks in advance for any help.

 

-Sandip

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to