Reputation: 1
numLogicalProcessors
on Intel core i7 is 8
(2 X 4 physical cores). Linux OS. So, eight OS threads(M
) can work in parallel. Go runtime can assign eight contexts(P1
, P2
....P8
- runtime.GOMAXPROCS(numLogicalProcessors)
) in my Go program.
Go follows M:N
threading model, where N
are OS threads and M
are go routines of a Go program.
OS scheduler schedules OS threads. Thread states are WAITING
, RUNNABLE
& EXECUTING
.
Go scheduler schedules Go routines. Go-routine states are WAITING
, RUNNABLE
& EXECUTING
. Goroutine is a user level thread.
Does the runtime of a Go program explicitly create those eight OS threads(M
)? before assigning each context(P
) to each OS thread(M
)?
If OS thread(M1
) is pre-empted(due to time-slice) by OS scheduler, How does goroutine scheduler(P1
) manage the state of goroutine G1
using LRQ? Does P1
get the notification from OS that M1
state has changed?
Upvotes: 2
Views: 1608
Reputation: 49241
Upvotes: 3