How can we start a real thread in gecko using javascript and use XPCOM in it?

Is dispatching events to /nsIStreamTransportService/ or /nsIThreadManager.newThread(0) /the right way?

--

Best regards,
??(Ray You)



-------- Original Message --------
Message-ID:     <50d1787d.8010...@mozilla.com>
Date:   Wed, 19 Dec 2012 16:19:09 +0800
From:   Ray You <r...@mozilla.com>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/17.0 Thunderbird/17.0
MIME-Version:   1.0
To:     doug.tur...@gmail.com
Subject:        A question about multithreading in gecko using javascript
Content-Type: multipart/alternative; boundary="------------060401050602000000060705"



Hi Doug,

I've read you DeviceStorage patch code, and believe that it really uses two threads, thus is really asynchronous, which means it would not be blocked by heavy IO operation. Plus it uses XPCOM components on another thread.

I believe the following code starts a new thread:

https://mxr.mozilla.org/mozilla-central/source/dom/devicestorage/nsDeviceStorage.cpp#1121

   nsCOMPtr<nsIEventTarget  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=nsIEventTarget>>target  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=target>  =do_GetService  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=do_GetService>(NS_STREAMTRANSPORTSERVICE_CONTRACTID  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=NS_STREAMTRANSPORTSERVICE_CONTRACTID>);
   NS_ASSERTION  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=NS_ASSERTION>(target,"Must
 have stream transport service");

   nsCOMPtr<InitCursorEvent  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=InitCursorEvent>>event  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=event>  =new  InitCursorEvent  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=InitCursorEvent>(this,mFile  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=mFile>);
   target  <http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=target>->Dispatch(  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=>event  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=event>,NS_DISPATCH_NORMAL  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=NS_DISPATCH_NORMAL>);

However javascript version of this code is not working: Dispatching the event to /nsIThreadManager.currentThread///mainThread/ works, while dispatching it to /nsIStreamTransportService/ or /nsIThreadManager.newThread(0) /does not.


Is there anything missing? Could we really start a new thread and use XPCOM components in it using js?

I've been stuck on this for a while and have read mdn and mozwiki on threads. I also learn that we can't access XPCOM components in chrome worker. Your help would be greatly appreciated.

--
 Best regards,
??(Ray You)

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to