10 ms·
WebAssembly Threads ready to try in Chrome 70
- m1el 8y agoWhat happened to concerns on Spectre/Meltdown being exploitable through high-resolution timers implemented through shared buffers/multithreading in Chrome?
- gok 8y agoI believe the solution is treating same-process code as same-security code, as probably always should have been the case.
- mmastrac 8y agoAccording to [1] > Note that SharedArrayBuffer was disabled by default in all major browsers on 5 January, 2018 in response to Spectre. Chrome re-enabled it in v67 on platforms where its site-isolation feature is enabled to protect against Spectre-style vulnerabilities. [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- feross 8y agoFixed by these: - Site Isolation (https://www.chromium.org/Home/chromium-security/site-isolation https://www.chromium.org/Home/chromium-security/site-isolati...) - Cross-Origin Read Blocking (https://www.chromium.org/Home/chromium-security/corb-for-developers https://www.chromium.org/Home/chromium-security/corb-for-dev...)
- bzbarsky 8y agoIt's not fully fixed by those, for what it's worth; I'm happy to provide examples outside a public venue. Chrome just decided it doesn't care about the security holes it's creating in websites. Other browsers are working on rolling out other mitigations they consider security-critical before being OK with re-enabling SharedArrayBuffer.
- ArtWomb 8y agoVery cool. I remember using the pthread flag from C. But I don't ever recall provisioning a set number of thread pool workers at compile time. Assume that will change at some point.
- deckarep 8y agoHow does synchronization or the lack of it carry over and translate to WASM based threading? I’m assumming all the typical threading problems are inherited by design such as the potential for deadlocks, memory corruption, priority inversion...etc? Also I’m assumming these threads will allow true parallelism to occur?
- simcop2387 8y agoExactly right, everything sharing the same sharedarraybuffer will have all those same issues and will run in parallel. It's a space that I suspect newer languages like go, rust, d, etc will start to really make a mark on wasm because of the concurrency models and other safety features that they contain.
- mathw 8y agoWithout true parallelism there'd be no point dealing with all the mess the raw threading primitives get you! But yes, it's basically good old pthreads in WebAssembly, with all the snake pits that implies. Although I would hope the runtimes will be robust enough that this can't take out the browser when you trip over a concurrency bug.
- ddtaylor 8y agoI tried searching does anyone know if this is available in Firefox yet?
- willglynn 8y agoNope: https://bugzilla.mozilla.org/show_bug.cgi?id=1389458 https://bugzilla.mozilla.org/show_bug.cgi?id=1389458 WebAssembly threads mostly depend on SharedArrayBuffer, which was yanked by everyone for security reasons. Chrome rearranged their browser memory model and re-enabled it, which let them deliver this feature while everyone else still has blockers. https://caniuse.com/#feat=sharedarraybuffer https://caniuse.com/#feat=sharedarraybuffer
- pretty_bubbles 8y agohttps://rustwasm.github.io/2018/10/24/multithreading-rust-and-wasm.html https://rustwasm.github.io/2018/10/24/multithreading-rust-an...
- markdog12 8y agoAs it says in pretty_bubbles link, enable javascript.options.shared_memory in about:config
- bzbarsky 8y agoTo be clear, Chrome re-enabled it without implementing mitigations that other browsers are likely to consider a basic requirement before re-enabling. A clear case of product or marketing trumping security...
- Waterluvian 8y agoWhat's a solid language choice for targetting wasm if I want to kick the tires? Go?
- lytedev 8y agoRust or C++ were easiest when I tried it last.
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- willglynn 8y agoRust has a pretty great WebAssembly story: https://rustwasm.github.io/book/ https://rustwasm.github.io/book/ Learning Rust at the same time as Rust+WebAssembly might be a bit of a reach, though.
- jake_the_third 8y agoIs there documentation on Rust+WebAssembly that is presented more like a conventional book or tutorial? I don't do well with example-driven documentation like these. Resources like the original rust book are excellent though.
- singularity2001 8y agoIs there really that much to learn? You can just target WebAssembly like this: cargo +nightly build --target wasm32-unknown-unknown
- majewsky 8y agoOkay, then how do I run that? How do I interface with the JS/DOM world? (Those are rhetorical questions. I just mean to show that there is, in fact, more to learn.)
- kodablah 8y agoQuick notes... The threads feature is in proposed status vs others that are in implementation status [0], but I assume this has been implemented before things like multi-value. I wonder why threads first, I assume just for experimentation. It should be noted that threads are essentially atomic memory accesses and wait/notify, nothing for starting a worker inside of WASM or anything, that is still in JS land. The test cases don't appear to include wait/wake nor does the test case interpreter that I saw [1]. Also, "Report issues" in the blog post links to https://TBD https://TBD. 0 - https://github.com/WebAssembly/proposals https://github.com/WebAssembly/proposals 1 - https://github.com/WebAssembly/threads https://github.com/WebAssembly/threads
- tree_of_item 8y agoThe example in the article creates a thread. Is that what you mean by "starting a worker"? Because it does seem to be able to do that.
- markdog12 8y agoJust to clarify, it creates Web Workers with JavaScript which share a WebAssembly instance. This plumbing is done automatically when compiled with Emscripten with the correct flags. You can't just take code that spawns threads, create and run a single WebAssembly instance and have it work without something like Emscripten that will do this plumbing for you. It must be done via Web Workers, which are heavyweight, so you wouldn't want to be spawning lots of them.
- deleted 8y ago[deleted]
- danShumway 8y agoMy understanding is that the atomic memory operations you're talking about are a big step towards enabling more interesting features in the future. I did a glancing read of the overall spec a while back and I remember seeing a few asides to the effect of "we'll have to tackle this as part of the threads effort." Take it with a grain of salt though, I'm still digging into this stuff.
- Sephr 8y agoI hope WebAssembly threads are only enabled in contexts where site isolation is active, lest we have another Spectre.
- natorion 8y agoYes, atomics and SABs are tied to SI being active.
- denormalfloat 8y agoSo, what's the memory model going to be? Without guarantees about the safety of operation, how can anyone reason about the safety of the program?
- teraflop 8y agoSome discussion here: https://github.com/WebAssembly/threads/issues/9 https://github.com/WebAssembly/threads/issues/9 tl;dr if WASM shared memory is specified to follow the same rules as SharedArrayBuffer, then atomic operations are sequentially consistent. Normal memory accesses in the presence of data races may be inconsistent, but they are still constrained (e.g. they must obey happens-before relationships).
- thefounder 8y agoDoes this mean we can have MPV or VLC compiled to WASM?
- singularity2001 8y agoIn theory absolutely. Just compiled a mid-size cpp project without any major hurdles.
- markdog12 8y agoOne nice feature missing that's important for video decoding efficiency is SIMD. It's being worked on, but not ready yet: https://github.com/WebAssembly/simd https://github.com/WebAssembly/simd
- zamadatix 8y agoNote the use case of this is pretty limited without a direct API to access GPU accelerated decoding. Otherwise you can basically decode on the CPU or fake it by rendering HTML video and copying that buffer into the application skin.
- deleted 8y ago[deleted]
- nevi-me 8y agoThere's no mention of whether applications will gracefully degrade if there's no threads support. What happens in that case? Or should developers have to check whether threads are enabled?
- natorion 8y agoDevs need to do feature detection like with any other feature e.g. for the presence of atomics and sharedarraybuffers.
- Animats 8y agoAre the first WebAssembly attacks out yet?
- de_watcher 8y agoOk, Qt/QML is happier now.
- oever 8y agoHow so?
- jamesfmilne 8y agoDocumentation on how this is implemeneted in emscripten: https://kripken.github.io/emscripten-site/docs/porting/pthreads.html https://kripken.github.io/emscripten-site/docs/porting/pthre...
- Jyaif 8y agoDoes that translate in having support for std::thread?
- jamesfmilne 8y agoYes, as std::thread is built on pthreads (for platforms which use pthreads, like emscripten.)
- ToFab123 8y agoEvery time I hear the word Webassembly I always imagine that one day the browser itself will be written in/compiled to webassembly and eventually the entire operating system will be too. Isn't that the natural end game for webassembly?
- danmaz74 8y agoRegarding the OS, experience tells me this won't happen - very specialised tools are almost always better at very specialised tasks.
- colek42 8y agoyour wait is over. https://bellard.org/jslinux/vm.html?url=https://bellard.org/jslinux/win2k.cfg&mem=192&graphic=1&w=1024&h=768 https://bellard.org/jslinux/vm.html?url=https://bellard.org/...
- fiedzia 8y agoIts a bad idea. You will ignore all the benefits of running native code: performance and access to low level features.You will not gain portability because every platform will have different APIs - those are not part of wasm project.
- pjmlp 8y agoThat bad idea is how mainframes user space applications work, and is partially adopted across watchOS, Android, ChromeOS, webOS, Windows/UWP and Garmin apps.
- fiedzia 8y agoIts certainly not how the OS and its runtime works. It may make sense when you have to support range of different hardware architectures, but its not really something you want to have by design. Limited range of supported hardware and native code will always be better.
- 8y ago
- jetzzz 8y agoWhy illustrate it with a program which has undefined behavior? It has signed integer overflow.