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

Fixed lazy loading thread safety #35529

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

Conversation

henriquewr
Copy link

Added sync for lazy loading

Fixes #35528

 - Added sync for lazy loading

Fixes dotnet#35528
@henriquewr henriquewr requested a review from a team as a code owner January 25, 2025 03:45
@henriquewr
Copy link
Author

@dotnet-policy-service agree

@AndriySvyryd AndriySvyryd self-assigned this Jan 25, 2025
@roji roji changed the title Fixed #35528 Fixed lazy loading thread safety Jan 25, 2025
var willWait = true;
TaskCompletionSource taskCompletionSource;

lock (_isLoadingLock)
Copy link
Author

Choose a reason for hiding this comment

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

i don't know exactly why
but i need do lock the access to the GetOrAdd, otherwise the code breaks again
my guess it's because of the implementation of GetOrAdd which are 2 separete methods

if (!TryGetValueInternal(tables, key, hashcode, out TValue? resultingValue))
{
    TryAddInternal(tables, key, hashcode, valueFactory(key), updateIfExists: false, acquireLock: true, out resultingValue);
}

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.

Lazy loading is not thread safe
2 participants