Permalink
Browse files

add sample goroutine

  • Loading branch information...
1 parent 8d3077b commit 757b29faa40bc7c0882771e5d46e6191d83d5712 @kicool committed Mar 13, 2012
Showing with 57 additions and 0 deletions.
  1. +40 −0 goroutine/gort1.go
  2. +17 −0 goroutine/gort3.go
View
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "time"
+)
+
+func server(i int) {
+ for {
+ print(i)
+ time.Sleep(1*1e9)
+ }
+}
+
+/*
+* this will no output if default: export GOMAXPROCS=1
+ */
+func f1() {
+ go server(1)
+ go server(2)
+ for {}
+}
+
+func f3() {
+ go server(1)
+ go server(2)
+ for {
+ time.Sleep(1*1e6)
+ }
+}
+
+func f2() {
+ go server(1)
+ go server(2)
+ time.Sleep(6*1000*1000)
+}
+
+func main() {
+ f3()
+ //f2()
+}
View
@@ -0,0 +1,17 @@
+package main
+
+import (
+ "time"
+ "fmt"
+)
+
+func IsReady(what string, minutes int64) {
+ time.Sleep(minutes * 60 * 1e9) // Unit is nanosecs.
+ fmt.Println(what, "is ready")
+}
+
+func main() {
+ go IsReady("tea", 6)
+ go IsReady("coffee", 2)
+ fmt.Println("I'm waiting...")
+}

0 comments on commit 757b29f

Please sign in to comment.