结构概览 defer type _defer struct { siz int32 // 参数的大小 started bool // 是否执行过了 sp uintptr // sp at time of defer pc uintptr fn *funcval _panic *_panic // defer中的panic link *_defer // defer链表,函数执行流程中的defer,会通过 link这个 属性进行串联 } panic type _panic struct { argp unsafe.Pointer // pointer to arguments of deferred call run during panic; cannot move - known to liblink arg interface{} // argument to panic link *_panic // link to earlier panic recovered bool // whether this panic is over aborted bool // the panic was aborted } g 因为 defer panic 都是绑定在 运行的g上的,所以这里说明一下g中与 defer panic相关的属性
IG 最初由几位知名 PHP 框架开发者发起,在吸纳了许多优秀的大脑和强健的体魄后,提出了 PSR-0 到 PSR-4 五套 PHP 非官方规范: PSR-0 (Autoloading Standard) 自动加载标准 PSR-1 (Basic Coding Standard) 基础编码标准 PSR-2 (Coding Style Guide) 编码风格向导 PSR-3 (Logger Interface) 日志接口 PSR-4 (Improved Autoloading) 自动加载优化标准
package main import “fmt” func main() { defer println(“defer 1”) defer func() { fmt.Println(“defer2.1”) println(“defer2”) }() defer println(“defer3”) }