Sobes.tech
Junior — Senior

Unsafe concurrent access to shared variables

livecode

Task condition

Determine what value will be output by the program when it runs.

func main() {
    var highest int

    for counter := 1000; counter > 0; counter-- {
        go func() {
            if counter % 2 == 0 && counter > highest {
                highest = counter
            }
        }()
    }

    fmt.Printf("Maximum is %d", highest)
}