title: How can we use channels in Go in place of mutex?
body: <p>Channels combine communication—the exchange of a value—with synchronization—guaranteeing that two calculations (goroutines) are in a known state.</p>
  
  <p>How is it possible to use the channels in Google Go to perform the functionality of mutex?</p>
  
  <pre><code>package main
  
  import "sync"
  
  var global int = 0
  var m sync.Mutex
  
  func thread1(){
      m.Lock()
      global = 1
      m.Unlock()
  }
  
  func thread2(){
      m.Lock()
      global = 2
      m.Unlock()
  }
  
  func main(){
     go thread1()
     go thread2()
  }
  </code></pre>