Created
January 24, 2015 14:12
-
-
Save sugilog/b0003b134a05e86d88f5 to your computer and use it in GitHub Desktop.
Goroutines:ポインタ
This file contains 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" | |
"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