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

CRITICAL Incorrect application of interlocked increment #18

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

michael-michalski
Copy link
Contributor

The static integer might be incremented additionally between the atomic operation and its application in a parallel scenario. It is the result of the atomic operation, which contains the correct value.

https://learn.microsoft.com/en-us/dotnet/api/system.threading.interlocked.increment?view=net-8.0

Returns
UInt32

The value of the variable immediately after the increment operation finished.

@michael-michalski michael-michalski changed the title Incorrect application of interlocked increment CRITICAL Incorrect application of interlocked increment Nov 11, 2024
@aevitas
Copy link
Owner

aevitas commented Nov 11, 2024

Good catch. Did you run into any actual instances of this occurring? The odds seem incredibly small, though I agree it is theoretically possible for two threads to read the same increment in the current implementation.

@KrFriis
Copy link

KrFriis commented Nov 11, 2024

Oops, I was going fast through a review, and a coworker had sent this to me.
I accidentally approved this, I cannot figure out how to revoke whatever I did.

My bad.

@michael-michalski
Copy link
Contributor Author

michael-michalski commented Nov 11, 2024

Yes, it occurred in a real scenario :)

@aevitas aevitas merged commit 68b9e56 into aevitas:master Nov 11, 2024
1 check passed
@aevitas
Copy link
Owner

aevitas commented Nov 11, 2024

Yes, it is based on an event from the trenches :)

Hope it wasn't too bad, thanks for the PR - I'll get a release out asap

@michael-michalski
Copy link
Contributor Author

I found a fairly quick remedy, thank you :)

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.

3 participants