Compiling a lightweight concurrency framework for C++11

93 views
Skip to first unread message

Shane Douglas

unread,
Dec 23, 2017, 5:31:34 AM12/23/17
to emscripten-discuss
I have been trying to get Async++ which is a lightweight concurrency framework for C++11 compiled under emscripten :- https://github.com/Amanieu/asyncplusplus/wiki. The library states that all it requires is a C++11 compiler and standard library so I believe that it should be possible to do so using pthreads and asm.js. I have managed to compile the library using "-O2 --memory-init-file 0 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=8 -std=c++11 -Wall -Wextra -pedantic -fno-rtti" and link it to a small test program but it does not seem to work. The test program runs fine natively in linux but when I try and use the emscripten version in a browser it ends up sending a browser thread to 100% cpu and I have to kill it. Obviously some of the synchronization is not working correctly but I don't see why that should be so since the library only requires C+11 and emscripten supports that. I am using Chrome Version 63.0.3239.84 (Official Build) (64-bit) and emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.37.22, clang version 4.0.0  (emscripten 1.37.22 : 1.37.22), Target: x86_64-unknown-linux-gnu, Thread model: posix. I realise that this is a very wide question but I was wondering if someone could give me some guidance as to whether what I am trying to do should be possible or not. I am aware that Javascript doesn't support the full range of memory orderings that C+11 does but I would have thought it should still work with somewhat less performance.

Thanks, Shane.

Alon Zakai

unread,
Dec 24, 2017, 1:47:02 PM12/24/17
to emscripten-discuss
It should be possible, but since threads support in browsers is not stable yet, this hasn't been tested thoroughly. So you may be encountering either a browser bug or a toolchain bug.

For the browser possibility, I'd test in another browser. If that has the same bad result, it's probably a toolchain issue we are not aware of. You can add some debug statements around the pthreads calls, to see what's going on, for example.

On Sat, Dec 23, 2017 at 2:31 AM, Shane Douglas <shane....@pointerra.com> wrote:
I have been trying to get Async++ which is a lightweight concurrency framework for C++11 compiled under emscripten :- https://github.com/Amanieu/asyncplusplus/wiki. The library states that all it requires is a C++11 compiler and standard library so I believe that it should be possible to do so using pthreads and asm.js. I have managed to compile the library using "-O2 --memory-init-file 0 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=8 -std=c++11 -Wall -Wextra -pedantic -fno-rtti" and link it to a small test program but it does not seem to work. The test program runs fine natively in linux but when I try and use the emscripten version in a browser it ends up sending a browser thread to 100% cpu and I have to kill it. Obviously some of the synchronization is not working correctly but I don't see why that should be so since the library only requires C+11 and emscripten supports that. I am using Chrome Version 63.0.3239.84 (Official Build) (64-bit) and emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.37.22, clang version 4.0.0  (emscripten 1.37.22 : 1.37.22), Target: x86_64-unknown-linux-gnu, Thread model: posix. I realise that this is a very wide question but I was wondering if someone could give me some guidance as to whether what I am trying to do should be possible or not. I am aware that Javascript doesn't support the full range of memory orderings that C+11 does but I would have thought it should still work with somewhat less performance.

Thanks, Shane.

--
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-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shane Douglas

unread,
Dec 28, 2017, 4:43:26 AM12/28/17
to emscripten-discuss
Alon,

Thanks for the reply. I managed to figure out my problem was due to the thread local storage losing the plot. The library was built for cross platform support, specifically IOS so it was pretty easy to compile without using TLS. Once I did that it started working on both Chrome and Firefox. Not sure if emscripten pthreads is supposed to support TLS ? Anyway I seem to be able to use it now at least experimentally so I am happy. Look forward to seeing emscripten/WebAssembly complete support for c++ threading and atomics.

Great product guys,
Shane.
Reply all
Reply to author
Forward
0 new messages