// Unrestricted access to shared memory among threads // It is as bad an idea in Go as it is in any other // language // // The basic idea here is to start a bunch of thread and // have them all increment a single variable // // Author: gtowell // Created: August 2022 package main import ( "fmt" "sync" ) // the variable to be abused by the threads var counter int64 func main() { // this is used to make sure that all threads are finished // this is pretty much equivalent to the latch mechanism in Java var wg sync.WaitGroup threads:= 10 // number of threads to start times := 1000000000 // number of increments to do in each thread pFunc := func() { // say the thread is done when the function completes // roughly same as java wrapping function in try..finally defer wg.Done() for th:=0; th