Pthreads in the V8 shell

65 views
Skip to first unread message

Zoltan Varga

unread,
Jun 29, 2019, 6:48:54 AM6/29/19
to emscripten-discuss
Hi,

 It looks like recent versions of V8's JS shell support web workers, so it is possible to run emscripten+pthreads in this shell. This is useful for running test suites which
use threads as it requires less work than running in the browser.

Ran into the following problems:
- the message received by onmessage () is not wrapped in a 'data' property. This might be a bug in D8.
- the main threads onmessage () seems to be only called when control returns to the main loop which never seems to happen in the JS shell, so the 'loaded' message
  is never received by the main thread, so startup fails. Worked around it by receiving the message synchronously using worker.getMessage () and passing it to
  onmessage (). Couldn't find too much documentation on getMessage (), is it a V8 extension ?

Here is a commit with the changes:

Wanted to discuss these isues before making it into a PR.

                    Zoltan


Alon Zakai

unread,
Jul 2, 2019, 5:02:53 PM7/2/19
to emscripte...@googlegroups.com
Thanks, I didn't know the V8 shell had this!

After asking some people, it sounds like this can indeed be useful for us. It isn't intended to be identical to the Web API for Workers, but it is not a temporary API, so we can rely on it for testing.

 -  I think we'd need to work around any API differences like that .data thing, by checking if we are in "ENVIRONMENT_IS_SHELL" etc.
 - The synchronous getMessage is a special d8 extension, yeah - if it's useful for us then no reason not to use it (but yeah, such things are probably not well documented except in the source...).

PR sounds great!

- Alon


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/95c693a4-7d24-4e40-9bff-7ea1e960daa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Johnson

unread,
Jul 8, 2019, 1:05:31 PM7/8/19
to emscripte...@googlegroups.com
This is (potentially) great news; being able to test wasm-threads code via d8 (rather than a full browser interaction) would make future Halide support for threading much easier to support. But is this a deliberate, long-term commitment on the part of V8 to provide enough WebWorker support to support wasm threading? (We wouldn't entertain using this otherwise.)

Alon Zakai

unread,
Jul 8, 2019, 2:32:53 PM7/8/19
to emscripte...@googlegroups.com
I don't think it's quite that official, as it appears undocumented. But I have heard that they use it internally and don't plan to change it. So it's on par with all of d8 basically, which is not standardized/documented, but still very useful.

Another option is to try to get node Workers working. I have some wip stuff in the node-pthreads branch, but I ran out of time - would be great if someone else can look at that. Basically, the challenge is that logging etc. is impossible when the main thread blocks, which makes it very hard to debug. But it might be possible to get working. (d8's nonstandard blocking APIs make things easier)

- Alon



Sam Clegg

unread,
Jul 10, 2019, 1:24:53 PM7/10/19
to emscripte...@googlegroups.com
I think its a lot more interesting to support threads in node that in
d8. node is widely used and has official releases. d8 is designed as
an internal testing tool for v8 a IIUC nothing else.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpR0kdprd54PB0UoBU-ExcJKM8r7uyDAqxMdLoxc7sH4aA%40mail.gmail.com.

Steven Johnson

unread,
Jul 10, 2019, 1:40:44 PM7/10/19
to emscripte...@googlegroups.com

Alon Zakai

unread,
Jul 10, 2019, 7:05:57 PM7/10/19
to emscripte...@googlegroups.com
I agree node is much more interesting for those reasons. However, it may be much easier to do this in d8 since it has that custom synchronous API.

Reply all
Reply to author
Forward
0 new messages