Goroutine Pause or Halt

List the functions can stop or suspend the execution of current goroutine, and explain their differences.

Answer

  1. runtime.Gosched: give up CPU core and join the queue, thus will be executed automatically.
  2. runtime.gopark: blocked until the callback function unlockf in argument list return false.
  3. runtime.notesleep: hibernate the thread.
  4. runtime.Goexit: stop the execution of goroutine immediately and call defer, but it will not cause panic.