Concurrency in go

download Concurrency in go

of 27

  • date post

    28-Nov-2014
  • Category

    Technology

  • view

    2.577
  • download

    5

Embed Size (px)

description

Concurrency in goFrom: https://docs.google.com/present/view?id=df36r82q_5gdq5gzth&pli=1

Transcript of Concurrency in go

  • 1. Concurrency in Go (or, Erlang done right)

2. Programming Model

  • Mostly CSP/-calaculus (not actually formalized): goroutines+channels
  • Go concurrency motto:
  • "Do not communicate by sharing memory; instead, share memory by communicating"
  • + Full-fledged shared memory

3. Goroutines

  • Thinkthreads(however nojoinoperation)
  • gofoo()
  • gologger.Printf("Hello, %s!", who)
  • gofunc() {
  • logger.Printf("Hello, %s!", who)
  • ... }()

4. Channels

  • Basically typed bounded blocking FIFO queues.
  • // synchronous chan of ints
  • c := make(chan int)
  • // buffered chan of pointers to Request
  • c := make(chan *Request, 100)

5. Channels: First-class citizens

  • You can pass them as function arguments, store in containers, pass via channels, etc.
  • Moreover, channels are not tied to goroutines. Several goroutines can send/recv from a single channel.

6. Channels: input/output

  • func foo(c chan int) {
  • c