Pthread support is added and can already be used with a small amount of settings. Since std :: thread uses pthread under the hood, you can also use it. See this discussion for more information.
What I had to do:
- Use new emscripten (I am testing with 1.34.1)
- Install Firefox at night
- Enable flag USE_PTHREADS
- Remember that this is experimental, and some things are finishing in nature.
I had a problem writing a pthread example that actually ran, but here's the code using std :: thread, which demonstrates the basic functionality that worked for me:
// main.cpp
I managed to use threads in a larger project (for a larger one for posting here!), So they are viable. Iβm afraid itβs not so fast, although it may improve over time.
To build it:
emcc main.cpp -o main.html -s USE_PTHREADS = 1 --std = C ++ 11
Output in Firefox Nightly 42.0a1 (2015-07-16):
Preliminary allocation of 1 worker for pthread breed pool.
Preliminary allocation of 1 employee for the pthread pool pool.
Preliminary allocation of 1 employee for the pthread pool pool.
I am a thread! I am a thread! I am a thread!
source share