Created
July 13, 2014 07:48
-
-
Save Geal/00af6e5d3a7bf79e0444 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" | |
"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