-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Pthreads #3266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Pthreads #3266
Changes from all commits
Commits
Show all changes
278 commits
Select commit
Hold shift + click to select a range
3a1396c
Make memory allocation thread-safe. Add test.
juj f6ec01f
Fix a bug where pthread exit might get called twice due to a race con…
juj 5ed8605
Add a test for previous bug fix.
juj 5b85dfc
Fix typo in assert in pthread_cancel.
juj b044ac2
Fix browser.test_pthread_mutex expected return value.
juj deafe10
Add (non-working) test for old GCC atomic fetch_and_op builtin operat…
juj f63fdc2
TEMP: fastcomp does not have __sync_fetch_and_nand, so implement it f…
juj 0c692f1
TEMP: Route GCC atomic fetch and op builtins to library functions to …
juj 4c76081
Add test for GCC old atomic builtin __sync_op_and_fetch instructions.
juj 8b07c45
TEMP: Implement __sync_op_and_fetch builtins in the test browser.test…
juj 4e8ac20
Add test for the remaining GCC atomics.
juj dc30616
TEMP: Fix up GCC atomics in browser.test_pthread_gcc_atomics to be pr…
juj 281f27f
Implement atomic operations for internal musl libc use for the JS arch.
juj 51f795e
Implement __wake and __wait musl libc internal futex operations for E…
juj 1f4069c
Implement pthread_once() from musl.
juj 01d4a45
Add test for pthread_once()
juj d05db20
Implement a_swap and a_fetch_add for internal musl libc atomics for t…
juj b8fe785
Fix typo in previous commit.
juj 963bc7a
Add pthread barrier API from musl.
juj c126ff9
Add test for pthread barriers.
juj 362e5fc
Implement musl pthread control structure for each created pthread.
juj fb4b1e9
Add support for thread local storage.
juj d7c47b1
Add support for pthread condition variables and add a test.
juj 96cd3bc
Add support for pthread read-write locks. TODO: Add a test.
juj 1d0e9af
Add support for pthread spinlocks. TODO: Add a test.
juj e7ee3d6
Add musl semaphore implementation. TODO: Add test.
juj 2015020
Remove custom directives for GCC atomic ops tests since these are now…
juj d126f92
Remove Atomic cas and fence emulation support in GCC atomics test, si…
juj 2a9d6fc
Add test file for Mandelbrot threading test.
juj 2da6a86
Temporarily disable non-pthread arraybuffer creation, because the if(…
juj 2a44747
Comment out functions that don't exist in the latest threading spec.
juj 7364b19
Make return value of emscripten_futex_wait() match the integers from …
juj da98c3f
Remove the old unnecessary atomics polyfill.
juj 53cdde8
Import global Atomics object to asm.js
juj 206204b
Remove handwritten JS implementations for atomics that are now implem…
juj c288dfb
Mark down a note that pthread start signatures are known to be differ…
juj 9466df9
Add primitive support for alarm() signal.
juj 43e5abd
Add stubs for sched_get_priority_min() and sched_get_priority_max()
juj 21b46a8
Restore the default pthread startup function form.
juj 0da4bc8
Add a hack to detect whether pthread is 'v' or 'vi'.
juj b9e52f9
Mimic linux thread scheduling parameters.
juj 457f3f4
Implement pthread_get/setschedparam.
juj d36826f
Implement pthread_setschedprio.
juj 998c7d8
Remove pthread_once from JS code, since it's implemented in musl.
juj c51e4ee
Implement stubs for pthread_sigmask and sigpending.
juj 7cff836
Make --emrun compatible with -lpthread.
juj d23f60b
Add support for pthread joinable status at thread creation. Improve p…
juj f9dee02
Fix pthread_create with PTHREAD_CREATE_JOINABLE.
juj 00b975d
Add better check for ENVIRONMENT_IS_PTHREAD versus ENVIRONMENT_IS_WOR…
juj 82b86cb
Refactor the creation of a pthread into a separate function so that i…
juj e3c134f
Fix bad offset for thread detach state attr.
juj f8a7639
Fix default detach state to PTHREAD_CREATE_JOINABLE for newly created…
juj 7ca0f87
Fix return codes for threads.
juj 6ec73b1
Replace assert() in pthread_cancel with proper error handling.
juj 0e82c8d
Implement pthread_detach.
juj c1784bb
Mark down TODO in pthread_exit.
juj f8fe238
Remove the use of custom 'joinable' attribute on threads, and reuse t…
juj d71ec47
Add new link setting -s PTHREAD_POOL_SIZE=<int> which specifies the n…
juj b035d9d
Add -s PTHREAD_POOL_SIZE=8 to test runner.
juj 2dbe6ce
Fix typo in pthread_cancel that caused it to fail.
juj 997bbef
Fix pthread_detach to return ESRCH instead of EINVAL when attempting …
juj 6a9a030
Run destructors of thread-specific data when a pthread exits.
juj a43f296
Implement pthread_getcpuclockid error result according to spec.
juj 7f2ff5a
If a pthread gets canceled, mark the thread return code to be PTHREAD…
juj ea527e2
Clarify hack.
juj e21444e
Fix typo in pthread quit.
juj e768a12
Migrate pthread schedPrio and schedPolicy from handwritten JS structu…
juj cf083f9
Fix wrong expression in pthread_detach.
juj 37b1153
Fix pthread_detach to allow detaching a thread that has already quit …
juj d7a9dd4
Fix emrun postjs to not try to do a http post when running the file o…
juj e0dfe95
Fix an issue where TLS data would get deleted from unallocated data s…
juj 3753d40
Add stub no-op pthread_atfork that does nothing since fork() is not s…
juj 41ae531
Change musl pthread_attr_getstack to be standard conforming.
juj 5d3f21d
Fix pthread_getschedparam, pthread_setschedparam and pthread_setsched…
juj c510272
Implement support for pthread_attr_setinheritsched.
juj d702c36
Add missing deps in pthread_create.
juj 5f24780
Add debug prints to pthread_join.
juj 9d42bed
Fix pthread_join to properly be able to join a thread that was cancel…
juj 00d5398
Add coverage in sleep&usleep for supporting cooperative thread cancel…
juj 51645b2
Remove an assert in pthread_testcancel to a benign no-op form.
juj 4f29d30
Implement pthread_setcancelstate() and pthread_setcanceltype().
juj 8354aa1
Migrate to musl pthread_mutex implementation.
juj ec7fcf6
Fix the meaning of var allocatedOwnStack to be proper.
juj 826bb06
Manually initialize filesystem in pthread workers so that they can do…
juj 2d59eda
Add test for printf in pthreads.
juj 02e33e5
Fix interpretation of musl thread stack base address to take into acc…
juj e61ade1
Add a sanity check assert to pthread stack creation.
juj e22adb6
Fix an issue with FS initialization in pthreads, and only initialize …
juj 5dffd80
Fix issues with TTY creation in pthreads.
juj 62dce5f
Maintain space for tempDoublePtr in pthreads. Fix allocatedOwnStack s…
juj d9abe64
Fix musl behavior of pthread_attr_setschedpolicy to return EINVAL on …
juj 98f4cb4
Fix pthread_setcancelstate to not be a cancellation point.
juj d71e127
Fix pthread_join to properly wait for thread to finish execution in t…
juj f2189bf
Fix pthread_join to properly return ESRCH after joining a thread that…
juj 7ba85ae
Fake support for sending signal 0 (no signal) to main thread with pth…
juj 30f787d
Properly return ESRCH from pthread_kill when attempting to kill a thr…
juj bcee732
Add error checking to range of signals in pthread_kill.
juj dedaca2
Impose limits on scheduler priorities in pthread_setschedparam and pt…
juj 3b28b28
Update Emscripten futex api to latest version and fix up pthread_cond…
juj 1be3070
Fix build error in test_pthread_malloc.cpp
juj 67a6978
Build pthread libraries as part of musl libc instead of rebuilding th…
juj 5bb55c6
Implement stub for clock_getcpuclockid.
juj d6f208c
Fix pthread_setschedprio reference to priority and update input check…
juj 3eb0093
Add test for TLS operation in the main thread.
juj e639945
Fix TLS operation in the main thread.
juj 5a7f79b
Fix TLS storage allocation for main thread.
juj 7baa4cb
Set sysconf(_SC_THREAD_PRIORITY_SCHEDULING) to return 0 to denote tha…
juj 848390b
Fix uppercase typo in pthread_join.
juj b45caf1
Restore custom mutex implementation which works better for Emscripten…
juj 4835e84
Add stub entries for unsupported pthread_mutexattr_get/setprioceiling.
juj e4d3138
Add new control field to musl mutex in order to implement JS futex ba…
juj b51aa91
Initialize main thread thread block better so that the fields are ava…
juj 4327892
Fix typo with missing parentheses.
juj 000c792
Implement support for recursive mutexes and unlocking an errorcheck m…
juj c62be35
Add support for PTHREAD_MUTEX_ERRORCHECK.
juj 212ce07
Fix pthread_mutex_unlock to return EPERM on error check mutexes if th…
juj af1c598
Fix pthread_mutex_trylock/timedlock handling of mutex ownership and u…
juj d96149d
Fix pthread_mutex_timedlock() interpretation of parameter 'at'. Retur…
juj fc191ee
Fix pthread_mutex_timedlock to return EINVAL if tv_nsec is wrong.
juj a550eb0
Add new (failing) test for volatile float and volatile double loads a…
juj 59ad37f
Add a new (failing) test that checks that a pthread is able to spawn …
juj 6f07b00
Implement support for pthreads to spawn other pthreads. Remove use of…
juj 2e6ef40
Fix freeing of pthread data.
juj bfdd11e
Use the pthread_t self parameter to identify whether a pthread_t stru…
juj 440a812
Add support for sibling threads to pthread_kill each other.
juj 4bea8fd
Enable sibling pthreads to pthread_cancel() each other.
juj d9a5309
Enable sibling pthreads to pthread_detach() each other. Improve error…
juj 64fc147
Enable main thread to call pthread_exit() (routes to exit()).
juj 59c15b1
Make __pthread_self be an alias to pthread_self since the two functio…
juj df5f1a1
Enable threads to call pthread_get/schedparam/prio on their sibling p…
juj ffb75f7
Fix main thread pthread_t block initialization of self parameter.
juj 64088da
Migrate pthread_setcanceltype/state, pthread_testcancel and usleep to…
juj aed6cdf
Make pthread_join a cancellation point. Add a temp hack to duplicate …
juj c867776
Fix the timeout value computation when waiting for a futex in __timed…
juj d86e9b3
Migrate back to musl mutex, which is now working better. Overload ems…
juj 96f3d4a
Fix futex wait value in usleep to actually sleep and not spinlock.
juj ed8119f
Remove the -1 semantic on emscripten_futex_wake, and instead use INT_…
juj 6df5c61
Remove obsolete __pthread_self().
juj 83c3b48
Implement cooperative thread cancellation testing to musl pthread mut…
juj 7282535
Improve musl rwlock to return EDEADLK instead of hanging/deadlocking …
juj aff64f2
Revise pthread cancellation point checks: usleep() must be a cancella…
juj d2bb705
Fix pthread wait issues with cancellation which caused semaphores not…
juj 0c9b6ac
When running pthread cleanup handlers, make thread cancellation defer…
juj 174a082
Implement a machinery to defer C file IO calls from pthreads to the E…
juj 1dbac7a
Implement proxying of all library.js C runtime functions to Emscripte…
juj cd41b65
Add browser test for file IO in pthreads.
juj b45d9a8
Update mandelbrot sample.
juj c985137
Remove obsolete pthread stub functions from library.js
juj 0d15d1f
Add 4-6 arg deferred execution handlers. Add a postMessage for deferr…
juj c1f1717
Add functions to emulate HEAPF32 and HEAPF64 Atomic loads and stores …
juj 1483d84
Use futex-based sleep to in test_pthread_mutex to work around bug htt…
juj 9fdeb94
Improve debug comment.
juj aa783c6
When the main thread of the C runtime quits e.g. with exit(), kill al…
juj e835df2
Fix a bug in setup of the ENV variable that caused spawned pthreads t…
juj 86b7039
Add a runtime check to static/dynamicAlloc functions to ensure that p…
juj ee9b66e
Test both forms of sleeping (spinlock with performance.now() and fute…
juj b799894
Improve mandelbrot demo to allow dynamically configuring the number o…
juj 8e422c5
Initial wip SSE implementation of mandelbrot.
juj 3dc5c3c
SSE update to Mandelbrot demo.
juj b9c5311
Mandelbrot improvements.
juj 37d5e6e
Smooth outputted performance in Mandelbrot to give a more stable read…
juj fdf1d0f
Add new function read_and_preprocess(filename) to tools/shared.py to …
juj 41783a0
Preprocess proxyClient.js when importing it.
juj 7149c71
Fix src/parseTools.js preprocessing to understand quotes in include s…
juj 5da5c1b
Pass the new JSBackend command line flag -emscripten-enable-pthreads …
juj 63ca02e
Separate pthreads implementation into its own pthreads.bc so that it'…
juj 58de76c
Add a test print to malloc test.
juj b997dea
Build dlmalloc either as thread safe or thread unsafe depending on wh…
juj 103ee47
Only import Atomics and SharedArrayBuffer to asm.js module if USE_PTH…
juj 65e5a9e
Properly instantiate either SharedIntXArray or IntXArray depending on…
juj 10777fd
Only import the Atomics functions to asm.js module if USE_PTHREADS is…
juj ebbe6b7
Add the original dummy implementation of pthread functions as src/lib…
juj 2ae040d
Add usleep to the pthread stub library functions.
juj b94b3b3
Update the expected result of sysconf test.
juj 3e1f110
Remove non-shared versions of typed array views from the asm.js modul…
juj 3eac339
Whitespace cleanup in emcc.
juj d50185a
Rename EM_DEFERRED_* to EM_PROXIED_* to better reflect that the calls…
juj d2caa92
In library.js, do not refer to ENVIRONMENT_IS_PTHREAD when not buildi…
juj 6570aeb
Remove unneeded nonexistent dependency to emscripten_get_now_is_monot…
juj 929ecd7
Use !== in clock_getcpuclockid().
juj 577401a
Update formatting and comments.
juj 7f10d23
Refer to ENVIRONMENT_IS_PTHREAD in src/preamble.js only if compiling …
juj 00d542d
Use strict equals comparison for thread message passing commands.
juj 7cbea08
Code syntax formatting.
juj 737efa1
Add a comment explaining the added new control field to pthread_mutex…
juj 996f689
Don't refer to ENVIRONMENT_IS_PTHREADS if not building with pthreads …
juj fa107e3
Use 'var' for ENVIRONMENT_IS_PTHREAD in src/shell.js.
juj 91fc9ad
Fix more references to ENVIRONMENT_IS_PTHREAD when not compiling with…
juj e5e55b8
Include gets() when building library_pthread.c with LLVM 3.6 and C11.
juj 213b9a1
Add missing else in library_pthread.js that resulted in a bogus error…
juj 0e657b8
Adjust to pthreads API change in futex wait operation: the timeout va…
juj 1b8662b
Fix signature typo in EM_PROXIED_PUTS.
juj 3b93da8
Process queued calls in usleep() to assist C runtime calls from pthre…
juj 01a463c
Remove references to the deleted getwd() function.
juj d3c7af9
Update documentation for pthreads.
juj ff51e66
Add a note about pthread-main.js deployment.
juj e2fc742
Rename threadBlock to threadInfoStruct to reflect the usage better.
juj 454db94
Document the existence of the __EMSCRIPTEN_PTHREADS__ preprocessor de…
juj 0b146e1
Fix missing '.bc' suffixes when including pthreads symbols to build.
juj b57729e
Allocate tempDoublePtr for the worker at worker init time.
juj 85999dd
Remove unnecessary if (typeof SharedArrayBuffer != 'undefined') test…
juj fde70c1
Remove reference to ENVIRONMENT_IS_PTHREAD in function getenv() when …
juj 7bbb6a6
Skip testing Atomic NAND for now at least, LLVM 3.6 attempts to suppo…
juj d21e7de
Allocate tempDoublePtr for pthreads via malloc, since the runtime is …
juj eb359e6
Skip nand portion of test_pthread_gcc_atomic_op_and_fetch test, since…
juj ddb3511
Add new test for iostream operation with pthreads. https://bugzilla.m…
juj cd0a6dc
Don't add static initializers to atinit when running in pthreads.
juj a1cfef9
Force-skip ensureInitRuntime() in all cases when running in pthreads …
juj 5af0de2
Mark static memory area to be immediately sealed on pthreads to make …
juj 0e32b72
Add support to JS libraries to specify a variable with syntax myVar: …
juj 091f758
Implement new machinery with PthreadWorkerInit variable that stores a…
juj 645755f
Add pthreads specific debug/error print to print an error stack trace…
juj 671784f
Fix several global variables from src/library.js to be properly carri…
juj 3b99bb7
Fix printf, fprintf and dprintf with varargs from pthreads.
juj abb3d70
Implement pthread_getattr_np, and add a test.
juj 0f03b22
Improve test test_pthread_atomics to cover 32bit load, store and cas …
juj 4dadeef
Add emulation for more 64bit atomic operations.
juj fe751d8
Fix tools/system_libs.py syntax after pthreads rebase.
juj ec44f9a
Remove stray leftover line "#endif // POINTER_MASKING" in src/preambl…
juj 1b047d9
Improve src/parseTools.js preprocess() function to report file:line d…
juj e10f77f
Readapt tools/system_libs.py adding for pthreads and malloc to work a…
juj 3cf5532
Add test file for browser.test_pthread_64bit_atomics.cpp.
juj 1384a73
Add emulated support and testing for 64-bit GCC atomic op intrinsics.
juj d0f91f6
Use document.currentScript to locate the current script file instead …
juj db1f776
Fix an issue where nested pthread spawns could not be immediately pth…
juj 824450b
Fix an issue where multiple threads allocating lots of memory (enough…
juj ec4edf3
Fix emscripten_main_thread_process_queued_calls() to not process same…
juj a58c2fe
Add emscripten_atomic_swap intrinsics. Add support for GCC __sync_loc…
juj 8ceb2b2
Add testing of Emscripten intrinsics in the spinlock test. Fix test_p…
juj c0304d5
HACK: Atomics.exchange() is not yet implemented, so as a temp workaro…
juj 29ecfad
Build pthread tests with -O3 to catch any potential optimizer interac…
juj b3687b9
Optimize emulated 64bit atomic ops by using a spinlock instead of pth…
juj 00c32b7
Polyfill SharedArrayBuffer.slice() operation which doesn't exist curr…
juj f11be16
Add support for preprocessor #if < operation.
juj f2c2340
Add new functions emscripten_num_logical_cores() which returns the nu…
juj 204d37a
Add a shallow test for emscripten_num_logical_cores(); functionality.
juj eba1d21
Implement operator > for preprocessor.
juj 07213d7
Add support for asking the pthread warmup pool size at startup as wel…
juj ccafa0a
Remove the -lpthread setting, and only use -s USE_PTHREADS=1 to have …
juj c223827
Abort compilation if PROXY_TO_WORKER=1 is attempted with USE_PTHREADS=1.
juj 914f095
Fix test browser.test_pthread_create_pthread to close the test window…
juj 52072b4
Abort execution on a warning if pthreads is not supported in the brow…
juj fe15b39
Fix pthread_cleanup_push() to new API after rebase.
juj 5399f2a
Test that preprocessor define __EMSCRIPTEN_PTHREADS__ is actually pre…
juj e0cff8c
Clean up -s USE_PTHREADS detection in emcc.
juj 03cf47e
Apply coding conventions to pthreads: space after for().
juj afe2900
Restore missing test code in tests/test_browser.py that was removed i…
juj 80c8aae
Comment long #if-#else-#endif chains in src/preamble.js for clarity.
juj f87bd74
Mark linker options for dynamic linking unsupported with -s USE_PTHRE…
juj 8c6d6f5
When SharedArrayBuffer is not supported, give browser test runner a s…
juj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.. Pthreads support: | ||
|
||
============================== | ||
Pthreads support | ||
============================== | ||
|
||
Low level multithreading is currently supported in Firefox Nightly release channel via an experimental extension to JavaScript Web Workers. This is a work-in-progress research project, and the prototype specification can be located `here <https://docs.google.com/document/d/1NDGA_gZJ7M7w1Bh8S0AoDyEqwDdRh4uSoTPSNn77PFk/edit?usp=sharing>`. | ||
|
||
The proposed specification allows Emscripten applications to share the main memory heap between web workers. This along with primitives for low level atomics and futex support enables Emscripten to implement support for the Pthreads (POSIX threads) API. | ||
|
||
Compiling with pthreads enabled | ||
=============================== | ||
|
||
By default, support for pthreads is not enabled, since the specification is still in a prototyping stage. To enable code generation for pthreads, the following command line flags exist: | ||
|
||
- Pass the compiler flag -s USE_PTHREADS=1 when compiling any .c/.cpp files, AND when linking to generate the final output .js file. | ||
- Optionally, pass the linker flag -s PTHREAD_POOL_SIZE=<integer> to specify a predefined pool of web workers to populate at page preRun time before application main() is called. If -1 is passed to both PTHREAD_POOL_SIZE and PTHREAD_HINT_NUM_CORES, then a popup dialog will ask the user the size of the pool (useful for testing). | ||
- Optionally, pass the linker flag -s PTHREAD_HINT_NUM_CORES=<integer> to choose what the function emscripten_num_logical_cores(); will return if navigator.hardwareConcurrency is not supported. If -1 is specified here, a popup dialog will be shown at startup to let the user specify the value that is returned here. This can be helpful in order to dynamically test how an application behaves with different values here. | ||
|
||
There should be no other changes required. In C/C++ code, the preprocessor check #ifdef __EMSCRIPTEN_PTHREADS__ can be used to detect whether Emscripten is currently targeting pthreads. | ||
|
||
Special considerations | ||
====================== | ||
|
||
The Emscripten implementation for the pthreads API should follow the POSIX standard closely, but some behavioral differences do exist: | ||
|
||
- When -s PTHREAD_POOL_SIZE=<integer> is not specified and pthread_create() is called, the new thread will not actually start to run immediately, but the main JS thread must yield execution back to browser first. This behavior is a result of `#1049079 <https://bugzilla.mozilla.org/show_bug.cgi?id=1049079>`. | ||
|
||
- Currently several of the functions in the C runtime, such as filesystem functions like fopen(), fread(), printf(), fprintf() etc. are not multithreaded, but instead their execution is proxied over to the main application thread. Memory allocation via malloc() and free() is fully multithreaded though. | ||
|
||
- The Emscripten implementation does not support `POSIX signals <http://man7.org/linux/man-pages/man7/signal.7.html>`, which are sometimes used in conjunction with pthreads. This is because it is not possible to send signals to web workers and pre-empt their execution. The only exception to this is pthread_kill() which can be used as normal to forcibly terminate a running thread. | ||
|
||
- The Emscripten implementation does also not support multiprocessing via fork() and join(). | ||
|
||
- For web security purposes, there exists a fixed limit (by default 20) of threads that can be spawned when running in Firefox Nightly. `#1052398 <https://bugzilla.mozilla.org/show_bug.cgi?id=1052398>`. To adjust the limit, navigate to about:config and change the value of the pref "dom.workers.maxPerDomain". | ||
|
||
- Some of the features in the pthreads specification are unsupported since the upstream musl library that Emscripten utilizes does not support them, or they are marked optional and a conformant implementation need not support them. Such unsupported features in Emscripten include prioritization of threads, and pthread_rwlock_unlock() is not performed in thread priority order. The functions pthread_mutexattr_set/getprotocol(), pthread_mutexattr_set/getprioceiling() and pthread_attr_set/getscope() are no-ops. | ||
|
||
- One particular note to pay attention to when porting is that sometimes in existing codebases the callback function pointers to pthread_create() and pthread_cleanup_push() omit the void* argument, which strictly speaking is undefined behavior in C/C++, but works in several x86 calling conventions. Doing this in Emscripten will issue a compiler warning, and can abort at runtime when attempting to call a function pointer with incorrect signature, so in the presence of such errors, it is good to check the signatures of the thread callback functions. | ||
|
||
Also note that when compiling code that uses pthreads, an additional JavaScript file `pthread-main.js` is generated alongside the output .js file. That file must be deployed with the rest of the generated code files. | ||
|
||
Running code and tests | ||
====================== | ||
|
||
Any code that is compiled with pthreads support enabled will currently only work in the Firefox Nightly channel, since the SharedArrayBuffer specification is still in an experimental research stage before standardization. There exists two test suites that can be used to verify the behavior of the pthreads API implementation in Emscripten: | ||
|
||
- The Emscripten unit test suite contains several pthreads-specific tests in the "browser." suite. Run any of the tests named browser.test_pthread_*. | ||
|
||
- An Emscripten-specialized version of the `Open POSIX Test Suite <http://posixtest.sourceforge.net/>` is available at `juj/posixtestsuite <https://github.com/juj/posixtestsuite>` GitHub repository. This suite contains about 300 tests for pthreads conformance. To run this suite, the pref dom.workers.maxPerDomain should first be increased to at least 50. | ||
|
||
Please check these first in case of any issues. Bugs can be reported to the Emscripten bug tracker as usual. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should document this adding of the file in the
site/
dir somewhere. it's another file people will need to copy around etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, that needs to be mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added note.