Skip to content

Instantly share code, notes, and snippets.

@sugilog
Created January 24, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugilog/b0003b134a05e86d88f5 to your computer and use it in GitHub Desktop.
Save sugilog/b0003b134a05e86d88f5 to your computer and use it in GitHub Desktop.
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