官术网_书友最值得收藏!

Goroutine

It is the logical unit of execution that contains the actual instructions for our program/functions to run. It also contains other important information regarding the goroutine, such as the stack memory, which machine (M) it is running on, and which Go function called it. The following are some of the elements in the goroutine struct that might come in handy for this section:

// Denoted as G in runtime 
type g struct { 
    stack         stack // offset known to runtime/cgo 
    m               *m    // current m; offset known to arm liblink 
    goid           int64 
    waitsince   int64   // approx time when the g become blocked 
    waitreason string  // if status==Gwaiting 
    gopc          uintptr // pc of go statement that created this goroutine 
    startpc       uintptr // pc of goroutine function 
    timer         *timer  // cached timer for time.Sleep 
 
    // ... 
} 

An interesting thing to know is that when our Go program starts, a goroutine called main goroutine is first launched, and it takes care of setting up the runtime space before starting our program. A typical runtime setup might include things such as maximum stack size, enabling garbage collector, and so on.

主站蜘蛛池模板: 罗田县| 镇宁| 青河县| 丽江市| 吉安市| 临汾市| 鄯善县| 抚顺市| 沧州市| 信宜市| 介休市| 翁源县| 中宁县| 萝北县| 黄陵县| 凉山| 丹凤县| 红桥区| 乐陵市| 北碚区| 杂多县| 新营市| 石林| 兴隆县| 大关县| 中西区| 天峻县| 略阳县| 蒲江县| 开远市| 石河子市| 武川县| 丽水市| 广丰县| 嘉峪关市| 治多县| 白河县| 松桃| 合江县| 乌什县| 无为县|