Skip to content

Instantly share code, notes, and snippets.

@sugilog sugilog/sample.go
Created Jan 24, 2015

Embed
What would you like to do?
Goroutines:ポインタ
package main
import (
"fmt"
"time"
)
func pcounter( index int, count *int ) {
for i := 0; i < 5; i++ {
*count++
fmt.Println( index, i, *count );
time.Sleep(100 * time.Millisecond)
}
}
func counter( index int, count int ) {
for i := 0; i < 5; i++ {
count++
fmt.Println( index, i, count );
time.Sleep(100 * time.Millisecond)
}
}
func main() {
i := 0
go pcounter( 1, &i )
go pcounter( 2, &i )
go counter( 3, i )
time.Sleep(1000 * time.Millisecond)
fmt.Println( i )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.