-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Pthreads #3266
Pthreads #3266
Conversation
@@ -703,6 +707,7 @@ try: | |||
pre_js += open(shared.path_from_root('src', 'emrun_prejs.js')).read() + '\n' | |||
post_js += open(shared.path_from_root('src', 'emrun_postjs.js')).read() + '\n' | |||
|
|||
|
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.
newline here seems unnecessary
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.
Ops. Removed.
Very impressive work! Bunch of questions above. I am still getting into the code, the answers will help me. |
I'm interested in running threads with pthread API in emscripten. So I tried to build and run a sample pthread program and run posixtestsuite, but I failed to execute. Could you point what's wrong I did? I was using the browser FirefoxNightly 39.0a1 (2015-03-23) and emscripten/fastcomp on pthreads branch. testing with simple pthread programI fetched a pthread sample source code from http://en.wikipedia.org/wiki/POSIX_Threads I built html/js with emcc and run it with emrun.
The error below shows up continuously.
Here is the source code.
testing with posixtestsuiteI challenged to run tests in posixtestsuite (https://github.com/juj/posixtestsuite)
The test started well and launched Firefox, but the results are fail like following.
|
@gunyarakun: There is currently an undocumented issue that you will need to work around: in Firefox there is a limit to how many web workers you can spawn. This is bug https://bugzilla.mozilla.org/show_bug.cgi?id=1052398 . To work around this, navigate to |
@kripken: Thanks for the reviews, I think I should have addressed all of those in the new batch of commits. |
@juj: thank you for your advice. I changed dom.workers.maxPerDomain and toolkit.startup.max_resumed_crashes (for not showing the dialog to be safe mode) and posixtestsuite seemed working well. But the sample program following doesn't work well. Is my program wrong or is it a known problem?
|
… to call to sbrk()), while main thread is also doing memory management, would cause a deadlock where pthread and main thread would wait on each others' mutexes. Add a test.
… calls again and again if the call flow leads to multiple nested operations.
…k_test_and_set() and __sync_lock_release().
…thread_mutex to pass the test params to compilation.
…und, do it as u32 version with a CAS loop. TODO: revert this commit once https://bugzilla.mozilla.org/show_bug.cgi?id=1141986 lands.
…ently so that JS code that interacts with Emscripten HEAP when it is a SAB can operate normally.
…mber of detected logical cores on the system and emscripten_force_num_logical_cores() which allows overriding the value returned by this function. Add a new command line variable -s PTHREAD_HINT_NUM_CORES=x to allow choosing the default value when navigator.hardwareConcurrency is not supported.
…l, useful for testing purposes.
…only one build and link flag for threads.
…ser. Add new option -s IN_TEST_HARNESS=1 and have the test harness skip the pthread tests if run on a browser that doesn't support them.
…sent when building with pthreads enabled.
…ADS=1 (todo for later).
…mall delay to report test being skipped before the test window is closed so that the XHR request can reach the test harness.
The other pull request should be now in better shape. Rebased this on top of the latest incoming and reran the tests on my Windows box, which look ok. |
This set of commits implements initial pthreads library support for Emscripten code, and allows native code to utilize multithreading with the pthreads API. This backs on experimental research on the JavaScript SharedArrayBuffer and Atomics APIs from https://docs.google.com/document/d/1NDGA_gZJ7M7w1Bh8S0AoDyEqwDdRh4uSoTPSNn77PFk/edit?usp=sharing , and as such is preliminary and unsupported in other browsers except current Firefox Nightly builds. By default pthreads support is disabled, and the feature must be explicitly enabled by specifying the compiler flag -s USE_PTHREADS=1 and the linker flag -lpthread.
This is for experimental use only at the moment, since none of the threading specification has yet been standardized, and it may change a lot for the final proposal, even to the point of making large parts of this pull request obsolete.
This PR contains some unit tests, but more is available in https://github.com/juj/posixtestsuite (especially see emscripten-core/posixtestsuite@ed4bdd6 ), which contains ~300 unit tests for POSIX conformance for pthreads.
There is an accompanying pull request to the LLVM backend at emscripten-core/emscripten-fastcomp#67 .