Skip to content

Commit

Permalink
add sample goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
kicool committed Mar 13, 2012
1 parent 8d3077b commit 757b29f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
40 changes: 40 additions & 0 deletions goroutine/gort1.go
@@ -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()
}
17 changes: 17 additions & 0 deletions goroutine/gort3.go
@@ -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.