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

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.

主站蜘蛛池模板: 青浦区| 三河市| 大英县| 隆昌县| 台中县| 邵武市| 莒南县| 准格尔旗| 江北区| 绥芬河市| 天祝| 临汾市| 凌海市| 宁都县| 柘城县| 宿州市| 巨野县| 蚌埠市| 天峨县| 龙山县| 项城市| 阳曲县| 邢台县| 长岛县| 黑龙江省| 台湾省| 沙坪坝区| 江都市| 阳朔县| 韶山市| 夏邑县| 池州市| 嘉义县| 安丘市| 军事| 宜丰县| 娱乐| 建水县| 云南省| 慈溪市| 红安县|