当前位置:网站首页>【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延迟调度被执行。

边栏推荐
- Window object of BOM series
- JS event introduction
- Error installing mysqlclient module on MAC system
- J9 number theory: what factors determine the value of NFT?
- 560 和为 K 的子数组
- Comprehensive upgrade, all you can imagine is here -- JD API interface
- File “manage.py“, line 14 ) from exc
- Openpyxl merge cells
- Redis installation, cluster deployment and common tuning
- uniapp createSelectorQuery().select 获取返回null报错
猜你喜欢

一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力

Plato launched the LAAS protocol elephant swap, which allows users to earn premium income

Openpyxl library fill color

DocuWare 移动劳动力解决方案可帮助您构建新的生产力模式:随时随地、任何设备

【HCIP】重发布及路由策略的实验

Read the recent trends of okaleido tiger and tap the value and potential behind it

围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
![[MySQL] historical cumulative de duplication of multiple indicators](/img/22/1d5162e2c9636c9455138f2f39d150.png)
[MySQL] historical cumulative de duplication of multiple indicators

Use of resttemplate and Eureka

第二轮Okaleido Tiger热卖的背后,是背后生态机构战略支持
随机推荐
【搜索】—— 迭代加深/双向DFS/IDA*
Lombook User Guide
地下水、土壤、地质、环境人看过来
全面升级,你能想象的都在这————京东API接口
How to choose professional, safe and high-performance remote control software
560 和为 K 的子数组
[hcip] OSPF experiment under mGRE environment, including multi process bidirectional republication and OSPF special area
Window object of BOM series
JS event introduction
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
[MySQL] historical cumulative de duplication of multiple indicators
【HCIP】MGRE环境下OSPF实验,含多进程双向重发布及OSPF特殊区域
J9数字论:什么因素决定NFT的价值?
Redis installation, cluster deployment and common tuning
els 新的方块落下
Common functions and usage of numpy
ELS square movement
Subtotal of process thread coordination
PCL point cloud intensity image
How many of the top ten test tools in 2022 do you master
