当前位置:网站首页>【Golang】- runtime.Goexit()
【Golang】- runtime.Goexit()
2022-07-29 00:50:00 【JavaPub-rodert】
博主介绍: 自媒体 JavaPub 独立维护人,全网粉丝15w+,csdn博客专家、java领域优质创作者,51ctoTOP10博主,知乎/掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、
GoLang技术领域和副业。
文章目录
Go语言的并发模型基本上遵照了CSP模型,goroutine间完全靠channel通信,没有像Unix进程的wait或waitpid的等待机制,也没有类似“POSIX Thread”中的pthread_join的汇合机制,更没有像kill或signal这类的中断机制。每个goroutine结束后就自行退出销毁 ,不留一丝痕迹。
/** Goexit 调用runtime.goExit()将立即终止当前goroutine执行,调度器 确保所有已注册defer延迟调度被执行。 */
package main
import (
"fmt"
"runtime"
)
func main(){
go func(){
defer fmt.Println("A defer go")
func(){
defer fmt.Println("B defer go")
runtime.Goexit()
fmt.Println("B")
}()
fmt.Println("A")
}()//别忘了()
//阻塞,防止结束
for{
}
//输出
/** F:\goWorkSpace\study\05协程>go run 06_runtimeGoexit.go B defer go A defer go */
}
调用runtime.goExit()将立即终止当前goroutine执行,调度器确保所有已注册defer延迟调度被执行。

边栏推荐
- numpy.where() 用法和np.argsort()的用法
- body中基本标签
- vm options、program arguments、environment property
- 2022年最火的十大测试工具,你掌握了几个
- It is found that the data of decimal type in the database can be obtained through resultset.getdouble, but this attribute cannot be obtained through GetObject.
- 了解网址url的组成后 运用url模块、querystring模块和mime模块完善静态网站
- Embedded sharing collection 23
- Cloud native application comprehensive exercise
- els 到底停止
- Moonbeam上的多链用例解析——Derek在Polkadot Decoded 2022的演讲文字回顾
猜你喜欢

Third party login process of flask Weibo

PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益

Introduction to Elmo, Bert and GPT

5G 商用第三年:无人驾驶的“上山”与“下海”

Ruiji takeout project actual battle day01

【HCIP】两个MGRE网络通过OSPF实现互联(eNSP)

【HCIP】MGRE环境下OSPF实验,含多进程双向重发布及OSPF特殊区域

matplotlib中文问题

了解网址url的组成后 运用url模块、querystring模块和mime模块完善静态网站

Redis installation, cluster deployment and common tuning
随机推荐
nep 2022 cat
mysql 创建索引的三种方式
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
internship:用于类型判断的工具类编写
Pinduoduo can use many API interfaces
【搜索】—— 迭代加深/双向DFS/IDA*
明日无限计划,2022某公司元宇宙产品发布会活动概念策划方案
RHCE command practice (II)
AlphaFold揭示了蛋白质结构宇宙-从近100万个结构扩展到超过2亿个结构
Comprehensive upgrade, complete collection of Taobao / tmall API interfaces
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
【HCIP】重发布及路由策略的实验
Embedded sharing collection 23
vm options、program arguments、environment property
J9数字论:什么因素决定NFT的价值?
[search] - DFS pruning and optimization
[hcip] MPLS Foundation
我们总结了 3 大Nacos使用建议,并首次公开 Nacos 3.0 规划图 Nacos 开源 4 周年
BOM系列之定时器
Cloud native application comprehensive exercise
