
rwdy2008's recent timeline updates
 | | rwdy2008 V2EX member #102139, joined on 2015-03-03 18:38:21 +08:00 |
rwdy2008's recent replies
```
package main
import (
"fmt"
"sync"
"sync/atomic"
)
func main() {
fmt.Println("Start...")
var x int32
done := false
lock := new(sync.Mutex)
cond := sync.NewCond(lock)
cond.L.Lock()
go func() {
for {
if x%3 == 0 {
fmt.Println("A", x)
atomic.AddInt32(&x, 1)
if x > 3*10-3 {
return
}
}
}
}()
go func() {
for {
if x%3 == 1 {
fmt.Println("B", x)
atomic.AddInt32(&x, 1)
if x > 3*10-2 {
return
}
}
}
}()
go func() {
for {
if x%3 == 2 {
fmt.Println("C", x)
atomic.AddInt32(&x, 1)
if x > 3*10-1 {
dOne= true
cond.Signal()
}
}
}
}()
for !done {
cond.Wait()
}
return
}
```