Open nickva opened 6 months ago
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?
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.