Skip to content

runtime/race: should 32-bit atomic ops be flagged as racing with 64-bit atomic ops? #38881

@bcmills

Description

@bcmills

(Broken out from #5045 (comment).)

My instinct is that mixing 32-bit and 64-bit atomic ops on the same memory must not be allowed, because their implementations may differ on some 32-bit hardware. However, the race detector does not currently flag them.

For example, this program exits without error when run with go test -race using go version devel +9b189686 Tue May 5 05:13:26 2020 +0000 linux/amd64:

package main

import (
	"fmt"
	"runtime"
	"sync/atomic"
	"unsafe"
)

func main() {
	var x uint64
	xa := (*[2]uint32)(unsafe.Pointer(&x))
	xl := &xa[0]
	xh := &xa[1]

	done := make(chan struct{})
	go func() {
		atomic.StoreUint64(&x, 0xbadc0ffee)
		close(done)
	}()
	runtime.Gosched()
	x0 := atomic.LoadUint32(xl)
	x1 := atomic.LoadUint32(xh)

	<-done
	fmt.Printf("Stored %x; loaded %x.", *xa, [2]uint32{x0, x1})
}

CC @dvyukov @aclements @cherrymui

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.RaceDetectorcompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions