Implementation Of Mutex And pthread In Emscripten

544 views
Skip to first unread message

awt

unread,
Sep 8, 2015, 6:18:30 AM9/8/15
to emscripten-discuss
Hi,

I was just going thru the source when I noticed the presence of mutex in emscripten/system/include/libcxx/mutex and pthreads in emscripten/system/include/libc/pthread.h. Since the browser is single-threaded, may I know how do we implement mutexes and pthreads under the hoods? Do we really implement synchronization in a multi-threading context? Is this supported only in FireFox Nightly or in Chrome as well? Thanks.

Floh

unread,
Sep 8, 2015, 10:00:03 AM9/8/15
to emscripten-discuss
These used to be empty placeholder functions so that code would at least compile and link.

However, there *is* work going on to enable pthreads-style shared-memory-multithreading in emscripten and Firefox, see here: 


and here:

https://groups.google.com/forum/#!topic/emscripten-discuss/gQQRjajQ6iY

Unfortunately I didn't get around to try this out yet.

Cheers,
-Floh

Robert Goulet

unread,
Sep 8, 2015, 11:38:54 AM9/8/15
to emscripten-discuss
pthread implementation on its own in Emscripten seems to be working fine so far. The only problem we have for the moment is we can't use it with WebGL (Firefox Nightly). It produces an assert about the SharedArrayBuffer type not being a correct type argument for some GL calls.

awt

unread,
Sep 8, 2015, 10:46:17 PM9/8/15
to emscripten-discuss
Thanks for the reply. Do you know if threads are emulated using webworkers or setTimeout in Emscripten?

Robert Goulet

unread,
Sep 9, 2015, 11:54:35 AM9/9/15
to emscripten-discuss
They are using Web Workers, and that means you also need the SharedArrayBuffers from Firefox Nightly to make this work. This is not supported (yet) in Google Chrome AFAIK.

awt

unread,
Sep 14, 2015, 3:40:44 AM9/14/15
to emscripten-discuss
ok thanks.
Reply all
Reply to author
Forward
0 new messages