Skip to content

[Emscripten port] Fix core count logic for Emscripten+pthreads #6350

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 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/support/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ void ThreadPool::initialize(size_t num) {
}

size_t ThreadPool::getNumCores() {
#ifdef __EMSCRIPTEN__
#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)
// In an Emscripten build without pthreads support, avoid the overhead of
// including support code for the below runtime checks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really to be sure to avoid the cost why not keep the else/endif? That way you are not relying so much on linker magic to do what you hope it will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks, I opened #6355

return 1;
#else
#endif

size_t num = std::max(1U, std::thread::hardware_concurrency());
if (getenv("BINARYEN_CORES")) {
num = std::stoi(getenv("BINARYEN_CORES"));
}
return num;
#endif
}

ThreadPool* ThreadPool::get() {
Expand Down