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

Panic if Load() is called before Store() #102

Closed
Jacalz opened this issue Aug 1, 2021 · 2 comments
Closed

Panic if Load() is called before Store() #102

Jacalz opened this issue Aug 1, 2021 · 2 comments

Comments

@Jacalz
Copy link

Jacalz commented Aug 1, 2021

I am getting this error when Load() happens before a call to Store() (with bool as an example here).

[jacob@fedora fyne_demo]$ ./fyne_demo 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x816bba]

goroutine 1 [running, locked to thread]:
go.uber.org/atomic.(*Bool).Load(...)
	/home/jacob/go/pkg/mod/go.uber.org/[email protected]/bool.go:49

I would personally have expected this to behave similarly to a regular type that would have it's default value returned when trying to access it before it has been changed. This would make the package a lot more useful for my use cases as I can avoid a lot of constructors or sync.Once by just letting the atomic types be part of the struct fields and then stored when it changes.

@Jacalz Jacalz changed the title Panic if Load() is called befor Store() Panic if Load() is called before Store() Aug 1, 2021
@prashantv
Copy link
Collaborator

If Load() is called on an uninitialized atomic.Bool, it returns the default value, false,

	var b atomic.Bool
	fmt.Println(b.Load())

https://play.golang.org/p/qxakAGECo19

In your case, I think the issue is that you have a pointer to an atomic.Bool.

@Jacalz
Copy link
Author

Jacalz commented Aug 2, 2021

You're right. I must have accidentally left the point on there from before I rewrote it to use atomic. Sorry.

@Jacalz Jacalz closed this as completed Aug 2, 2021
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

No branches or pull requests

2 participants