...
1
2
3
4
5 package main
6
7
8
9
10
18 import "C"
19
20 import (
21 "runtime"
22 "sync"
23 )
24
25 func main() {
26 var wg sync.WaitGroup
27 var mu sync.Mutex
28 c := make(chan []C.char, 100)
29 for i := 0; i < 10; i++ {
30 wg.Add(2)
31 go func() {
32 defer wg.Done()
33 for i := 0; i < 100; i++ {
34 c <- make([]C.char, 4096)
35 runtime.Gosched()
36 }
37 }()
38 go func() {
39 defer wg.Done()
40 for i := 0; i < 100; i++ {
41 p := &(<-c)[0]
42 mu.Lock()
43 C.f(p)
44 mu.Unlock()
45 }
46 }()
47 }
48 wg.Wait()
49 }
50
View as plain text