Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @wolfcw
I'm opening this PR to share a patch that potentially addresses #327 and #130. I agree with your opinion that libjemalloc should be more resilient during initialization (it does not seem to support reentrancy when calling clock_gettime), but for use cases where we can't really patch Jemalloc, it could be useful to have an alternative.
This patch does the following:
init_pthread_cond_init_232
, loads only the necessary functions to use it; [1]clock_gettime
, loads onlyreal_clock_gettime
and calls that if not initalized; [1];calloc
andfree
use the internal__libc_*
functions if it didn't have a chance to load thereal_
before using.[1] that means it effectively does not initialize the library in these two functions.
Please let me know if there are any changes I can make to turn this into a mergeable fix. Even if you decide by not integrating it, I think it's good to have a reference point for anyone struggling with this issue.
PS: An alternative, simpler fix that works for some use cases, is to just syscall SYS_clock_gettime inside
clock_gettime
when not initialized, but then you also have to compile withoutFAKE_PTHREAD
(since Jemalloc depends on that too).