当前位置: 首页 > news >正文

导航网站搭建四川建筑人才招聘网

导航网站搭建,四川建筑人才招聘网,网络营销的分类,怎样做网站流量统计derfer : 延迟调用,函数结束返回时执行,多个defer按照先进后出的顺序调用 原理:底层通过链表实现,每次新增的defer调用,通过头插法插入链表;defer执行时,从链表头开始遍历,相当于实…

derfer : 延迟调用,函数结束返回时执行,多个defer按照先进后出的顺序调用

原理:底层通过链表实现,每次新增的defer调用,通过头插法插入链表;defer执行时,从链表头开始遍历,相当于实现了后加入的defer先执行,先加的defer后执行

defer结构体

type _defer struct {started boolheap    bool// openDefer indicates that this _defer is for a frame with open-coded// defers. We have only one defer record for the entire frame (which may// currently have 0, 1, or more defers active).openDefer boolsp        uintptr // sp at time of deferpc        uintptr // pc at time of deferfn        func()  // can be nil for open-coded defers_panic    *_panic // panic that is running deferlink      *_defer // next defer on G; can point to either heap or stack!// If openDefer is true, the fields below record values about the stack// frame and associated function that has the open-coded defer(s). sp// above will be the sp for the frame, and pc will be address of the// deferreturn call in the function.fd   unsafe.Pointer // funcdata for the function associated with the framevarp uintptr        // value of varp for the stack frame// framepc is the current pc associated with the stack frame. Together,// with sp above (which is the sp associated with the stack frame),// framepc/sp can be used as pc/sp pair to continue a stack trace via// gentraceback().framepc uintptr
}

defer初始化

// Create a new deferred function fn, which has no arguments and results.
// The compiler turns a defer statement into a call to this.
func deferproc(fn func()) {gp := getg()if gp.m.curg != gp {// go code on the system stack can't deferthrow("defer on system stack")}d := newdefer()if d._panic != nil {throw("deferproc: d.panic != nil after newdefer")}// 这里使用头插法 插入链表d.link = gp._defergp._defer = dd.fn = fnd.pc = getcallerpc()// We must not be preempted between calling getcallersp and// storing it to d.sp because getcallersp's result is a// uintptr stack pointer.d.sp = getcallersp()// deferproc returns 0 normally.// a deferred func that stops a panic// makes the deferproc return 1.// the code the compiler generates always// checks the return value and jumps to the// end of the function if deferproc returns != 0.return0()// No code can go here - the C return register has// been set and must not be clobbered.
}

defer执行

func deferreturn() {gp := getg()for {d := gp._deferif d == nil {return}sp := getcallersp()if d.sp != sp {return}if d.openDefer {done := runOpenDeferFrame(gp, d)if !done {throw("unfinished open-coded defers in deferreturn")}gp._defer = d.linkfreedefer(d)// If this frame uses open defers, then this// must be the only defer record for the// frame, so we can just return.return}fn := d.fnd.fn = nil// 指向下一个defer节点gp._defer = d.linkfreedefer(d)fn()}
}
http://www.yayakq.cn/news/729569/

相关文章:

  • 江苏网站建设网络推广dede被挂网站网站木马
  • 寮步网站建设提交网站到百度
  • 网站开发不懂英语成都广告设计公司电话
  • 中山企业网站建设银川注册公司流程和费用
  • 建设厅注册中心网站wordpress mysql配置文件
  • seo网站策划书电商网站是什么
  • 网站备案名称能重复吗百度视频下载
  • 网站商城建设报告一个网站3个相似域名
  • 大连模版网站论坛网站推广方案
  • 浙江网站建设上市公司网站模板开发主要作用
  • 有那个网站如何做一个好网站
  • 中国建设银行官方网站汇率自己制作网站做外贸赚钱吗
  • 外贸网络推广怎样做seo的优化原理
  • 免费行情软件网站大全入口没网站可以做seo吗
  • 网站优化方案和实施拖拽网站开发
  • 提交网站到谷歌网站设计)
  • 怎么更改网站的备案号wordpress悬浮小工具的插件
  • 门户网站建设工作室doaction wordpress
  • 苏州市规划建设局网站徐州网络优化招聘网
  • 如何在微信内做网站推广渠道有哪些方式
  • 企业网站建设兴田德润怎么联系建造师网
  • 利用国外网站文章图片做书营利成都注册公司需要什么材料和手续
  • 网站建设的费用包括重庆忠县网站建设公司哪家专业
  • 肃宁做网站价格敦煌网站销售员怎么做
  • 榆林公司网站建设新媒体营销ppt
  • 宝安建网站外包盐山县做网站
  • ip会变怎么做网站微信公众号小程序怎么做
  • c2c网站建设费用天将建设集团有限公司网站
  • 汉中专业做网站樟树有哪几个网站做爆药库
  • 公司平台网站建设宝安seo优化公司