File: consumer-publisher.go

package info (click to toggle)
ruby-em-synchrony 1.0.5-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 572 kB
  • sloc: ruby: 3,458; sh: 37; sql: 7; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 474 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
  "fmt"
  "runtime"
)

func producer(c chan int, N int, s chan bool) {
  for i := 0; i < N; i++ {
    fmt.Printf("producer: %d\n", i)
    c <- i
  }
  s <- true
}

func consumer(c chan int, N int, s chan bool) {
  for i := 0; i < N; i++ {
    fmt.Printf("consumer got: %d\n", <- c)
  }
  s <- true
}

func main() {
  runtime.GOMAXPROCS(2)

  c := make(chan int)
  s := make(chan bool)

  go producer(c, 10, s)
  go consumer(c, 10, s)

  <- s
  <- s
}