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

fix: avoid copy atomic value #8

Merged
merged 1 commit into from
Dec 12, 2024
Merged

fix: avoid copy atomic value #8

merged 1 commit into from
Dec 12, 2024

Conversation

medcl
Copy link
Member

@medcl medcl commented Dec 11, 2024

Fix warning: Call of 'task.RegisterScheduleTask' copies the lock value: type 'task.ScheduleTask' contains 'atomic.Bool' contains 'interface{}' which is 'sync.Locker'

This warning is a result of Go’s strict handling of types containing atomic fields or synchronization primitives (e.g., sync.Locker). When such types are copied, it can cause subtle bugs because the copied value shares access to underlying synchronization mechanisms or memory.

This pull request includes changes to the core/task/task.go file to improve the handling of the isTaskRunning field in task structures. The changes ensure that isTaskRunning is properly initialized as a pointer to an atomic.Bool.

Initialization improvements:

  • core/task/task.go: Added initialization of isTaskRunning as a pointer to an atomic.Bool in the registerTransientTask function.
  • core/task/task.go: Changed the isTaskRunning field in the ScheduleTask struct to be a pointer to an atomic.Bool instead of a direct atomic.Bool instance.
  • core/task/task.go: Added initialization of isTaskRunning as a pointer to an atomic.Bool in the RegisterScheduleTask function.

@luohoufu luohoufu self-assigned this Dec 12, 2024
Copy link
Contributor

@luohoufu luohoufu left a comment

Choose a reason for hiding this comment

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

LGTM

@medcl medcl requested a review from silenceqi December 12, 2024 02:47
@silenceqi silenceqi merged commit 7807b0a into main Dec 12, 2024
2 checks passed
@silenceqi silenceqi deleted the task7 branch December 12, 2024 12:39
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