If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Can't send strings to threads

RESOLVED INVALID

Status

()

Core
JavaScript Engine
RESOLVED INVALID
7 years ago
4 years ago

People

(Reporter: Erik Vold, Unassigned)

Tracking

Trunk
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
My extension Scriptish https://addons.mozilla.org/en-US/firefox/addon/231203/ implements Workers using threads which pass strings between threads, which no longer works because of bug 608142 which offers no alternative method to implement this.
We should be able to make this work for strings specifically by copying the string, I'd think.  Performance would possibly suck, but...
Blocks: 608142

Comment 2

7 years ago
Yeah, we can definitely allow strings through here. Erik, does that fix your use case?
(Reporter)

Comment 3

7 years ago
(In reply to comment #2)
> Yeah, we can definitely allow strings through here. Erik, does that fix your
> use case?

Yes that should be all that I need.

Comment 4

7 years ago
Just to be clear though, you can't send closures across. How do you execute code on a thread right now without workers?
(Reporter)

Comment 5

7 years ago
(In reply to comment #4)
> Just to be clear though, you can't send closures across. How do you execute
> code on a thread right now without workers?

https://github.com/erikvold/scriptish/blob/master/extension/modules/api/GM_worker.js#L156

I took a closer look at my implementation and have been thinking about this all night, and I am sharing objects atm.

At first I thought I could just pass messages + signatures to a singleton dispatcher, instead of making dynamic dispatchers as I am now, but now I'm wondering how to pass the string from the background thread to the dispatcher in the main thread, and atm I can't think of a way to do that..

Comment 6

7 years ago
(In reply to comment #5)
> ... but now I'm
> wondering how to pass the string from the background thread to the dispatcher
> in the main thread ...

That's not the actual problem here: While you can still create a background thread using newThread() you cannot (from js) dispatch any runnable code to this new thread. So in fact, you don't have a background thread (here: javascript implementation of nsIRunnable running on a background thread) that needs to dispatch anything back to the main thread ;)

In your code fake_worker.run is in fact never called as you're trying to execute instances of it on a |newThread(0)|. And that's exactly what bug 608142 doesn't permit any longer. Your |dispatch(this, ...)| fails silently[1].

The nsIThreadManager API is dead when it comes to creating new threads to execute js-implemented nsIRunnables.
There aren't any full-featured alternatives: Neither Workers nor JetPack processes allow XPCOM access.

[1]
https://github.com/erikvold/scriptish/blob/master/extension/modules/api/GM_worker.js#L74
Assuming this.thread points to a new thread, like it does right now.
(Reporter)

Comment 7

7 years ago
(In reply to comment #6)
> (In reply to comment #5)
> > ... but now I'm
> > wondering how to pass the string from the background thread to the dispatcher
> > in the main thread ...
> 
> That's not the actual problem here: While you can still create a background
> thread using newThread() you cannot (from js) dispatch any runnable code to
> this new thread.

So what can you do with a thread then?

> So in fact, you don't have a background thread that
> needs to dispatch anything back to the main thread ;)

huh?
(Reporter)

Updated

4 years ago
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.