Skip to content

Refactor to use atomic type#1019

Merged
VojtechVitek merged 1 commit intogo-chi:masterfrom
cuiweixie:atomic.Uint64
Sep 17, 2025
Merged

Refactor to use atomic type#1019
VojtechVitek merged 1 commit intogo-chi:masterfrom
cuiweixie:atomic.Uint64

Conversation

@cuiweixie
Copy link
Contributor

No description provided.

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

LGTM. Is there any benefit here beyond nicer syntax?

@cuiweixie
Copy link
Contributor Author

cuiweixie commented Sep 17, 2025

LGTM. Is there any benefit here beyond nicer syntax?

Encapsulation of atomic behavior:
The atomic.Uint64 type ensures that all accesses go through its safe methods, preventing unsafe reads/writes that could cause data races.

Less error-prone:
With the old approach, it was possible to mistakenly read or write reqid directly without atomic operations. With atomic.Uint64, you can’t access the underlying value without using its atomic methods.

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

Sounds good. So there was no issue with the existing code - but this change will prevent any future misuse.

LGTM. Thank you 👍

@VojtechVitek VojtechVitek merged commit 51c977c into go-chi:master Sep 17, 2025
10 checks passed
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.

2 participants