Skip to content

Instantly share code, notes, and snippets.

@tejiriaustin
Created May 22, 2024 14:18
Show Gist options
  • Save tejiriaustin/28d2f173e3bcb26d3e6585be792b28e6 to your computer and use it in GitHub Desktop.
Save tejiriaustin/28d2f173e3bcb26d3e6585be792b28e6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
var counter *int
func increment() {
for i := 0; i < 1000; i++ {
*counter++
}
}
func subtract() {
*counter -= 10
}
func main() {
a := 10
counter = &a
go increment()
fmt.Println("increment value:", *counter)
go subtract()
fmt.Println("subtract value:", *counter)
fmt.Println("Final counter value:", *counter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment