Skip to content
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

Add CONFIG_NO_WORKER Makefile option #300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nickva
Copy link
Contributor

@nickva nickva commented May 13, 2024

This option eliminates the dependency on the pthread library. This mode is already toggled on _WIN32 and/or when EMSCRIPTEN is detected, here we just allow the user to toggle it at will at the top level.

This slightly reduces the code size as well, and may allow compiling this library in some embedded contexts where pthread is not available or is broken.

@nickva
Copy link
Contributor Author

nickva commented May 13, 2024

As a bit of a background, I was inspecting one of my executables which embeds QuickJS and noticed in the symbols listing with nm -u it was showing a bunch of pthread symbols:

_pthread_cond_destroy
_pthread_cond_init
_pthread_cond_signal
_pthread_cond_timedwait
_pthread_cond_wait
_pthread_mutex_lock
_pthread_mutex_unlock

My code is not using any workers and was hoping with link-time optimization it wouldn't need to bring in pthreads at all.

Looking at QuickJS I noticed quickjs.c already has a mode to not include pthreads with CONFIG_ATOMICS, and in quickjs-lib.c there is USE_WORKER, which effectively does the same, so it seemed trivial to allow users to manually configure this mode via the Makefile.

I wasn't sure about the name, and since we have USE_WORKER already I opted for CONFIG_NO_WORKER but maybe something like NO_PTHREAD might be better?

TooTallNate pushed a commit to TooTallNate/quickjs that referenced this pull request Jul 3, 2024
- fix incorrect argument in s = `JSON.stringify(s);`
- add closures for `RegExp` and `JSON`
This option eliminates the dependency on the pthread library. This mode is
already toggled on _WIN32 and/or EMSCRIPTEN is detected, here we just allow the
user to toggle it at will at the top level.

This slightly reduce the code size as well, and may allow compiling this
library in some embedded contexts where pthread is not available or is broken.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant