Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does P mean in Go's sync.Pool source code?

Tags:

go

Recently, I've been digging into Go's source code. When I looked into the details of sync.Pool, I found a comment I couldn't understand.

https://golang.org/src/sync/pool.go?s=1633:1992#L58

// Local per-P Pool appendix.
type poolLocalInternal struct {
    private interface{}   // Can be used only by the respective P.
    shared  []interface{} // Can be used by any P.
    Mutex                 // Protects shared.
}

Local per-P Pool appendix.

What does per-P mean?

Can be used only by the respective P

What does P mean?

like image 716
jack-nie Avatar asked Mar 17 '18 03:03

jack-nie


1 Answers

P stands for processor. A processor is a resource used to execute Go code. There are exactly GOMAXPROC Ps in a process. The Go Scheduler Design Doc describes Ps in detail. The relevant code is in the runtime package.

like image 137
Bayta Darell Avatar answered Oct 14 '22 14:10

Bayta Darell