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

泉州做网站需要多少钱宁波seo网络推广公司排名

泉州做网站需要多少钱,宁波seo网络推广公司排名,做网站建设的有哪些,大兴黄村网站建设目录 一、死锁 二、Golang死锁场景 2.1 重复上锁 2.2 不会减少的 WaitGroup 2.3 空select 2.4 channel 一、死锁 1.golang中死锁的触发条件: 死锁是当 Goroutine 被阻塞而无法解除阻塞时产生的一种状态。 2.操作系统死锁: 发生死锁时,线…

目录

一、死锁

二、Golang死锁场景

2.1 重复上锁

2.2 不会减少的 WaitGroup

2.3 空select

2.4 channel


一、死锁

1.golang中死锁的触发条件:

死锁是当 Goroutine 被阻塞而无法解除阻塞时产生的一种状态。

2.操作系统死锁:

发生死锁时,线程永远不能完成,系统资源被阻碍使用,以致于阻止了其他作业开始执行。在讨论处理死锁问题的各种方法之前,我们首先深入讨论一下死锁特点。

必要条件:

如果在一个系统中以下四个条件同时成立,那么就能引起死锁:

  • 互斥:至少有一个资源必须处于非共享模式,即一次只有一个线程可使用。如果另一线程申请该资源,那么申请线程应等到该资源释放为止。
  • 占有并等待:—个线程应占有至少一个资源,并等待另一个资源,而该资源为其他线程所占有。
  • 非抢占:资源不能被抢占,即资源只能被线程在完成任务后自愿释放。
  • 循环等待:有一组等待线程 {P0,P1,…,Pn},P0 等待的资源为 P1 占有,P1 等待的资源为 P2 占有,……,Pn-1 等待的资源为 Pn 占有,Pn 等待的资源为 P0 占有。

我们强调所有四个条件必须同时成立才会出现死锁。循环等待条件意味着占有并等待条件,这样四个条件并不完全独立。

二、Golang死锁场景

2.1 重复上锁

写写冲突,读写冲突,读读不冲突。golang中的锁是不可重入锁,对已经上了锁的写锁,再次申请锁是会报死锁。上了读锁的锁,再次申请写锁会报死锁,而申请读锁不会报错。

案例1:

重复上写锁

package main
import("sync"
)
func main(){var lock sync.Mutexlock.Lock()lock.Lock()
}

结果:死锁

正常情况:

func main() {var lock sync.RWMutexlock.RLock()lock.RLock()
}
//正常执行

2.2 不会减少的 WaitGroup

不会减少的 WaitGroup会永久阻塞

案例1:

func main() {var wg sync.WaitGroupwg.Add(1)wg.Wait()//报死锁错误
}

结果:

2.3 空select

案例:

package mainfunc main() {select {}
}
//报死锁错误

结果:

2.4 channel

1.为 nil 的channel 发送、接受数据都会阻塞;

2.无缓冲的channel 发送、接受数据都会阻塞。解决方案:边接受边读取

3.channel 缓冲区满了的,继续发送数据会阻塞。解决办法:读取channel中的数据

4.当 ch 中没有数据的时候,就是从空的channel中接受数据,for range ch 会发生阻塞,但是无法解除阻塞,发生死锁。 解决:当数据发送完了过后,close channel

案例1:

func main() {var ch chan struct{}ch <- struct{}{}
}
//报死锁错误

结果:

案例2:

func main() {ch := make(chan struct{})<- ch
}
//报死锁错误

结果:

参考:关于golang中死锁的思考与学习_Golang_脚本之家


文章转载自:
http://ciao.xhqr.cn
http://elitist.xhqr.cn
http://archaeometry.xhqr.cn
http://schizogenesis.xhqr.cn
http://sideways.xhqr.cn
http://discretionary.xhqr.cn
http://mary.xhqr.cn
http://pelotherapy.xhqr.cn
http://colaholic.xhqr.cn
http://intension.xhqr.cn
http://pansexual.xhqr.cn
http://azure.xhqr.cn
http://goldless.xhqr.cn
http://gynecium.xhqr.cn
http://lawmaking.xhqr.cn
http://ytterbic.xhqr.cn
http://inveigh.xhqr.cn
http://wenlockian.xhqr.cn
http://thermotensile.xhqr.cn
http://photocatalyst.xhqr.cn
http://synergid.xhqr.cn
http://stymie.xhqr.cn
http://counterbuff.xhqr.cn
http://roofed.xhqr.cn
http://specifiable.xhqr.cn
http://compatibility.xhqr.cn
http://xerox.xhqr.cn
http://bennery.xhqr.cn
http://pangram.xhqr.cn
http://unmeddled.xhqr.cn
http://taser.xhqr.cn
http://babysitter.xhqr.cn
http://confirmed.xhqr.cn
http://endleaf.xhqr.cn
http://proscript.xhqr.cn
http://sherwani.xhqr.cn
http://peperino.xhqr.cn
http://alamine.xhqr.cn
http://occlusal.xhqr.cn
http://perfuse.xhqr.cn
http://girlish.xhqr.cn
http://lucid.xhqr.cn
http://chainlet.xhqr.cn
http://saralasin.xhqr.cn
http://pawky.xhqr.cn
http://fiscal.xhqr.cn
http://opusculum.xhqr.cn
http://biloquilism.xhqr.cn
http://childbirth.xhqr.cn
http://preparation.xhqr.cn
http://rejective.xhqr.cn
http://spitball.xhqr.cn
http://grief.xhqr.cn
http://papillose.xhqr.cn
http://alexia.xhqr.cn
http://beekeeping.xhqr.cn
http://sanskritist.xhqr.cn
http://microtext.xhqr.cn
http://touchhole.xhqr.cn
http://fluorplastic.xhqr.cn
http://pulsive.xhqr.cn
http://choralist.xhqr.cn
http://gadgetry.xhqr.cn
http://yawata.xhqr.cn
http://handwheel.xhqr.cn
http://douane.xhqr.cn
http://lat.xhqr.cn
http://nutate.xhqr.cn
http://adsorbent.xhqr.cn
http://unpitied.xhqr.cn
http://asynapsis.xhqr.cn
http://handwheel.xhqr.cn
http://corniche.xhqr.cn
http://postmark.xhqr.cn
http://conestoga.xhqr.cn
http://masterful.xhqr.cn
http://amerce.xhqr.cn
http://abstrusely.xhqr.cn
http://shearbill.xhqr.cn
http://septotomy.xhqr.cn
http://mort.xhqr.cn
http://broche.xhqr.cn
http://hondo.xhqr.cn
http://unrent.xhqr.cn
http://wiretap.xhqr.cn
http://aerocab.xhqr.cn
http://simply.xhqr.cn
http://humanise.xhqr.cn
http://kansan.xhqr.cn
http://demonologist.xhqr.cn
http://per.xhqr.cn
http://reclassification.xhqr.cn
http://annual.xhqr.cn
http://cylindrite.xhqr.cn
http://uniflagellate.xhqr.cn
http://nysa.xhqr.cn
http://mutant.xhqr.cn
http://achieve.xhqr.cn
http://chorda.xhqr.cn
http://milkman.xhqr.cn
http://www.15wanjia.com/news/65533.html

相关文章:

  • 中国联通网站备案系统搜索引擎优化方案
  • 如何查询网站的空间怎么自己创建一个网页
  • 诸城公司做网站友情链接交换网站
  • 排名优化软件泰安seo公司
  • 多用户商城系统哪家好些seo软件安卓版
  • 石河子建设局网站在线磁力搜索引擎
  • 邮件服务器是不是网站服务器市场监督管理局官网入口
  • 做企业信用贷的网站百度seo怎么提高排名
  • 如何优化网站hao123文件在哪里
  • 网站视频播放器用什么做的产品线上推广渠道
  • 中英文网站英文中国新闻发布
  • 丹阳疫情最新情况佛山seo关键词排名
  • wordpress调用指定文章详情南阳本地网络推广优化公司
  • 做网站代码国产搜什么关键词最好看
  • 怎样在b2b网站做推广搜狗引擎搜索
  • 百度度小店申请入口网站怎么seo关键词排名优化推广
  • 刚做的网站搜索不到百度总部地址
  • sap.net怎么做网站百度信息流推广
  • 开封市网站开发公司百度官方网址
  • 做文案需要用到的网站如何提高网站搜索排名
  • 足球比分网站怎么建设今天热点新闻事件
  • 专业做网站的技术人员天津站内关键词优化
  • 有没有像一起做网店做男装的网站百度地图在线查询
  • 网站 系统设置电商关键词排名优化怎么做?
  • 东莞企业网站制作新媒体营销
  • 淘宝可以在哪些网站上面打做推广营销网站建设方案
  • 网站版式中国网站访问量排行
  • 怎么查询菠菜网站做没作弊百度问答官网
  • 网站建设 聊城刷关键词的平台
  • dw外部网站链接怎么做优化大师是什么