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

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.

主站蜘蛛池模板: 芮城县| 布尔津县| 临潭县| 五莲县| 北安市| 沁阳市| 临夏市| 阿鲁科尔沁旗| 浦县| 鞍山市| 隆尧县| 兰考县| 卓资县| 铁岭县| 林州市| 巨野县| 南通市| 荣昌县| 万载县| 渭南市| 庄河市| 马龙县| 康保县| 泰州市| 南开区| 延寿县| 崇明县| 三原县| 进贤县| 隆化县| 嘉黎县| 贵溪市| 西城区| 禄丰县| 兰西县| 南充市| 潞城市| 仪陇县| 玉林市| 龙口市| 长宁县|