Skip to content

runtime/race: missed race on []Struct #4453

@dvyukov

Description

@dvyukov
The race in the following test is not detected, because slice operations imitate
accesses only to the beginning of each element, so it detects similar race on x[1].x but
not on x[1].y.

func TestRaceFailingSliceStruct(t *testing.T) {
    type X struct {
        x, y int
    }
    c := make(chan bool, 1)
    x := make([]X, 10)
    go func() {
        y := make([]X, 10)
        copy(y, x)
        c <- true
    }()
    x[1].y = 42
    <-c
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions