Created
May 22, 2024 14:18
-
-
Save tejiriaustin/28d2f173e3bcb26d3e6585be792b28e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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