Skip to content

Commit fd717f0

Browse files
authored
Remove PTHREAD_HINT_NUM_CORES (#10166)
We can assume almost all browsers have navigator.hardwareConcurrency these days, and basically all those where we can use pthreads (so not IE11).
1 parent 9f1d3f3 commit fd717f0

File tree

6 files changed

+2
-76
lines changed

6 files changed

+2
-76
lines changed

site/source/docs/porting/pthreads.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Compiling with pthreads enabled
1818
By default, support for pthreads is not enabled. To enable code generation for pthreads, the following command line flags exist:
1919

2020
- Pass the compiler flag ``-s USE_PTHREADS=1`` when compiling any .c/.cpp files, AND when linking to generate the final output .js file.
21-
- 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. This is important because if the workers do not already exist then we may need to wait for the next browser event iteration for certain things, see below. (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, which is useful for testing.)
22-
- 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.
21+
- 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. This is important because if the workers do not already exist then we may need to wait for the next browser event iteration for certain things, see below.
2322

2423
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.
2524

src/library_pthread.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,20 +582,12 @@ var LibraryPThread = {
582582
}
583583
},
584584

585-
_num_logical_cores__deps: ['emscripten_force_num_logical_cores'],
586-
_num_logical_cores: '{{{ makeStaticAlloc(4) }}}; HEAPU32[__num_logical_cores>>2] = navigator["hardwareConcurrency"] || ' + {{{ PTHREAD_HINT_NUM_CORES }}},
587-
588585
emscripten_has_threading_support: function() {
589586
return typeof SharedArrayBuffer !== 'undefined';
590587
},
591588

592-
emscripten_num_logical_cores__deps: ['_num_logical_cores'],
593589
emscripten_num_logical_cores: function() {
594-
return {{{ makeGetValue('__num_logical_cores', 0, 'i32') }}};
595-
},
596-
597-
emscripten_force_num_logical_cores: function(cores) {
598-
{{{ makeSetValue('__num_logical_cores', 0, 'cores', 'i32') }}};
590+
return navigator['hardwareConcurrency'];
599591
},
600592

601593
{{{ USE_LSAN || USE_ASAN ? 'emscripten_builtin_' : '' }}}pthread_create__deps: ['_spawn_thread', 'pthread_getschedparam', 'pthread_self', 'memalign'],

src/preamble.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -780,43 +780,6 @@ var memoryInitializer = null;
780780
#include "memoryprofiler.js"
781781
#endif
782782

783-
#if USE_PTHREADS && PTHREAD_HINT_NUM_CORES < 0
784-
if (!ENVIRONMENT_IS_PTHREAD) addOnPreRun(function() {
785-
addRunDependency('pthreads_querycores');
786-
787-
var bg = document.createElement('div');
788-
bg.style = "position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.8; opacity:.80; filter: alpha(opacity=80);";
789-
var div = document.createElement('div');
790-
var default_num_cores = navigator.hardwareConcurrency || 4;
791-
var hwConcurrency = navigator.hardwareConcurrency ? ("says " + navigator.hardwareConcurrency) : "is not available";
792-
var html = '<div style="width: 100%; text-align:center;"> Thread setup</div> <br /> Number of logical cores: <input type="number" style="width: 50px;" value="'
793-
+ default_num_cores + '" min="1" max="32" id="thread_setup_num_logical_cores"></input> <br /><span style="font-size: 75%;">(<span style="font-family: monospace;">navigator.hardwareConcurrency</span> '
794-
+ hwConcurrency + ')</span> <br />';
795-
#if PTHREAD_POOL_SIZE < 0
796-
html += 'PThread pool size: <input type="number" style="width: 50px;" value="'
797-
+ default_num_cores + '" min="1" max="32" id="thread_setup_pthread_pool_size"></input> <br />';
798-
#endif
799-
html += ' <br /> <input type="button" id="thread_setup_button_go" value="Go"></input>';
800-
div.innerHTML = html;
801-
div.style = 'position: absolute; top: 35%; left: 35%; width: 30%; height: 150px; padding: 16px; border: 16px solid gray; background-color: white; z-index:1002; overflow: auto;';
802-
document.body.appendChild(bg);
803-
document.body.appendChild(div);
804-
var goButton = document.getElementById('thread_setup_button_go');
805-
goButton.onclick = function() {
806-
var num_logical_cores = parseInt(document.getElementById('thread_setup_num_logical_cores').value);
807-
_emscripten_force_num_logical_cores(num_logical_cores);
808-
#if PTHREAD_POOL_SIZE < 0
809-
var pthread_pool_size = parseInt(document.getElementById('thread_setup_pthread_pool_size').value);
810-
PThread.allocateUnusedWorkers(pthread_pool_size, function() { removeRunDependency('pthreads_querycores'); });
811-
#else
812-
removeRunDependency('pthreads_querycores');
813-
#endif
814-
document.body.removeChild(bg);
815-
document.body.removeChild(div);
816-
}
817-
});
818-
#endif
819-
820783
#if PTHREAD_POOL_SIZE > 0 && PTHREAD_POOL_DELAY_LOAD != 1
821784
// To work around https://bugzilla.mozilla.org/show_bug.cgi?id=1049079, warm up a worker pool before starting up the application.
822785
if (!ENVIRONMENT_IS_PTHREAD) addOnPreRun(function() { if (typeof SharedArrayBuffer !== 'undefined') { addRunDependency('pthreads'); PThread.allocateUnusedWorkers({{{PTHREAD_POOL_SIZE}}}, function() { removeRunDependency('pthreads'); }); }});

src/settings.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,11 +1393,6 @@ var PTHREAD_POOL_DELAY_LOAD = 0;
13931393
// local vars in asm.js/wasm code.
13941394
var DEFAULT_PTHREAD_STACK_SIZE = 2*1024*1024;
13951395

1396-
// Specifies the value returned by the function emscripten_num_logical_cores()
1397-
// if navigator.hardwareConcurrency is not supported. Pass in a negative number
1398-
// to show a popup dialog at startup so the user can configure this dynamically.
1399-
var PTHREAD_HINT_NUM_CORES = 4;
1400-
14011396
// True when building with --threadprofiler
14021397
var PTHREADS_PROFILING = 0;
14031398

tests/pthread/test_pthread_num_logical_cores.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/test_browser.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,11 +3819,6 @@ def test_pthread_iostream(self):
38193819
def test_pthread_setspecific_mainthread(self):
38203820
self.btest(path_from_root('tests', 'pthread', 'test_pthread_setspecific_mainthread.cpp'), expected='0', args=['-s', 'TOTAL_MEMORY=64MB', '-O3', '-s', 'USE_PTHREADS=1'], also_asmjs=True)
38213821

3822-
# Test the -s PTHREAD_HINT_NUM_CORES=x command line variable.
3823-
@requires_threads
3824-
def test_pthread_num_logical_cores(self):
3825-
self.btest(path_from_root('tests', 'pthread', 'test_pthread_num_logical_cores.cpp'), expected='0', args=['-O3', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_HINT_NUM_CORES=2'], also_asmjs=True)
3826-
38273822
# Test that pthreads have access to filesystem.
38283823
@requires_threads
38293824
def test_pthread_file_io(self):

0 commit comments

Comments
 (0)