Skip to content

Instantly share code, notes, and snippets.

@Geal
Created July 13, 2014 07:48
Show Gist options
  • Save Geal/00af6e5d3a7bf79e0444 to your computer and use it in GitHub Desktop.
Save Geal/00af6e5d3a7bf79e0444 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"runtime"
"time"
)
type State struct {
counter int
}
func main() {
fmt.Println("ready? start!")
runtime.GOMAXPROCS(4)
var send = make(chan *State)
fmt.Println("lauching race")
go func() {
var s1 = &State{0}
fmt.Println("s1: ", s1.counter)
send <- s1
s1.counter = 1
fmt.Println("s1: ", s1.counter)
time.Sleep(5 * time.Second)
fmt.Println("s1: ", s1.counter)
}()
go func() {
s2 := <-send
time.Sleep(100 * time.Millisecond)
s2.counter = 3
fmt.Println("s2: ", s2.counter)
}()
time.Sleep(10 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment