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

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.

主站蜘蛛池模板: 福鼎市| 康马县| 海兴县| 渝中区| 镇沅| 贵定县| 天柱县| 依安县| 永吉县| 阿图什市| 昌江| 许昌县| 固安县| 余庆县| 平邑县| 南雄市| 阿拉善盟| 开阳县| 塔河县| 娄底市| 昌黎县| 始兴县| 吉木萨尔县| 江陵县| 板桥市| 金湖县| 永康市| 雅安市| 买车| 辽源市| 那曲县| 延川县| 阿拉善盟| 溧阳市| 天长市| 昌乐县| 夹江县| 连平县| 崇阳县| 涟源市| 泰和县|