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

Safer atomics usage #208

Merged
merged 1 commit into from
Apr 24, 2022
Merged

Safer atomics usage #208

merged 1 commit into from
Apr 24, 2022

Conversation

guregu
Copy link
Contributor

@guregu guregu commented Apr 23, 2022

I'm not an expert on atomics, but my understanding is that if you're doing atomic writes on an object you need to use atomics for reads too. I changed NewVariable to use atomic.AddUint64's return value instead of accessing the counter variable directly.

Feel free to ignore this if it's wrong. I tried to look up whether accessing global value types non-atomically after atomic writes was safe or not but I couldn't find much, but my gut instinct is that it's probably best avoided 🤔

@codecov-commenter
Copy link

Codecov Report

Merging #208 (1382d65) into main (f89c74e) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #208   +/-   ##
=======================================
  Coverage   96.68%   96.68%           
=======================================
  Files          20       20           
  Lines        6244     6244           
=======================================
  Hits         6037     6037           
  Misses        170      170           
  Partials       37       37           
Impacted Files Coverage Δ
engine/variable.go 95.23% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f89c74e...1382d65. Read the comment docs.

Copy link
Owner

@ichiban ichiban left a comment

Choose a reason for hiding this comment

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

This is exactly what I intended and failed. Looks great!

@ichiban ichiban merged commit 4f67e7a into ichiban:main Apr 24, 2022
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