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

sync/atomic: LoadInt64 panics on ARM when uint64 variable is not 64bit aligned #9959

Closed
Hades32 opened this issue Feb 22, 2015 · 6 comments
Closed

Comments

@Hades32
Copy link

Hades32 commented Feb 22, 2015

The following code works fine on Windows x86_64 and fails on Debian Jessie on a Raspberry Pi 2 ARMv7, both go version 1.4:

package main

import (
    "sync/atomic"
    "fmt"
)

type buffer struct {
        id int32 // remove this, or make it int64 and the code will run fine
        done int64
}

func test(buf *buffer) bool {
        if atomic.LoadInt64(&buf.done) == 1 {
                return true
        }

        return false
}
func main() {
        var buf buffer
                buf.done = 1
        fmt.Println("pre-fail")
        res := test(&buf)
        fmt.Println("post-fail", res)
}

Not sure if this is a bug in LoadInt64 or a bug in the go memory layouter...

@cespare
Copy link
Contributor

cespare commented Feb 22, 2015

From the bottom of the sync/atomic docs (the "Bugs" section):

On both ARM and x86-32, it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically. The first word in a global variable or in an allocated struct or slice can be relied upon to be 64-bit aligned.

@Hades32
Copy link
Author

Hades32 commented Feb 22, 2015

Looks like a typical case of RTFM then :)

Although, when it is listed in the docs as bug, why is there no bug in the bug tracker?

@adg
Copy link
Contributor

adg commented Feb 22, 2015

"Bug" is probably a stronger word than is necessary. "Caveat" is better, but godoc doesn't recognise // CAVEAT: comments.

@adg adg closed this as completed Feb 22, 2015
@mikioh mikioh changed the title atomic.LoadInt64 panics on ARM when uint64 variable is not 64bit aligned sync/atomic: LoadInt64 panics on ARM when uint64 variable is not 64bit aligned Feb 22, 2015
@minux
Copy link
Member

minux commented Feb 23, 2015 via email

@dvyukov
Copy link
Member

dvyukov commented Feb 23, 2015

@minux why is sp alignment required?
we still have not mark atomic ops as noescape, so they are always in heap

@minux
Copy link
Member

minux commented Feb 23, 2015 via email

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants