CS6963 Distributed Systems

Go Quiz

Write your name and UnID on your paper and answer the following two questions about this block of code.

package main

import "fmt"

const buffer = 0

func main() {
  a := make(chan int, buffer)
  b := make(chan int, buffer)
  done := make(chan int)

  go func() {
    a <- 1
    fmt.Printf("Left\n")
    <- b

    done <- 1
  }()

  go func() {
    <- a
    fmt.Printf("Right\n")
    b <- 1

    done <- 1
  }()

  <- done
  <- done
}

  1. What is the output of this code?
  2. What is the output of this code if const buffer = 0 is changed to const buffer = 1?