1 Threads, Processes, And Goroutines

Thread

  • share memory (virtual address space VAS) & resource
  • scheduled independently
  • if there are multiple CPUs, they can run simultaneously

Process

  • contains multiple threads
  • independent VAs

Goroutines

  • Go's version of threads
  • More lightweight than OS threads
    • OS context switches are expensive
    • Go scheduler switches between goroutines, cheap
  • Go runtime
    • assigns goroutines to OS threads
    • manages context switches of threads
    • maintains a queue of goroutines