Make sentinel value configurable in library/std/src/sys_common/thread_local_key.rs
#105359
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.
This is an excerpt of a changeset for the QNX/Neutrino OS. To make the patch for QNX smaller and easier to review, I've extracted this change (which is OS independent). I would be surprised if no other OS is also affected.
All this patch does is to define a
const
for a sentinel value instead of using it directly at several places.There are OSs that always return the lowest free value. The algorithm in
lazy_init
always avoids keys with the sentinel value.In affected OSs, this means that each call to
lazy_init
will always request two keys from the OS and returns/frees the first one (with sentinel value) immediately afterwards.By making the sentinel value configurable, affected OSs can use a different value than zero to prevent this performance issue.
On QNX/Neutrino, it is planned to use a different sentinel value:
It seems like no other OS defines
PTHREAD_KEYS_MAX
in Rusts libc, butlimits.h
on unix systems does.