What is the difference between Go’s multithreading and pthread or Java Threads?

Quoted from Day 3 Tutorial <- read this for more information.

Goroutines are multiplexed as needed
onto system threads. When a goroutine
executes a blocking system call, no
other goroutine is blocked.

We will do the same for CPU-bound
goroutines at some point, but for now,
if you want user-level parallelism you
must set $GOMAXPROCS. or call
runtime.GOMAXPROCS(n).

A goroutine does not necessarily correspond to an OS thread. It can have smaller initial stack size and the stack will grow as needed.

Multiple gorouitines may be multiplexed into a single thread when needed.

More importantly, the concept is as outlined above, that a goroutine is a sequential program that may block itself but does not block other goroutines.

Goroutines is implemented as pthreads in gccgo, so it can be identical to OS thread, too.
It’s separating the concept of OS thread and our thinking of multithreading when programming.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)