英文:
Key reasons for golang to make concurrency easier
问题
我的理解大致正确吗?
-
go
在编译时可以大部分检测到死锁
。 -
go
可以使用chan
来最小化竞态条件
,因为在任何特定的chan
上,只有单个发送者或接收者goroutine
可以同时访问。
英文:
Is my understanding roughly right below?
-
go
can mostly detectdead lock
at compile-time. -
That
go
can usechan
to minimizerace condition
is because only single sender or receivergoroutine
can have access to any specificchan
at a time.
答案1
得分: 3
我不会说那是准确的。关于死锁,编译时没有任何保证,如果你使用互斥锁不当,就会发生死锁,没有编译器可以防止这种情况。你可以很容易地测试竞态条件,但这是不同的问题。
关于第二点,通道会序列化你的异步操作,但我认为你的陈述并没有太多意义。一堆 goroutine 可以同时向通道写入和读取数据。它就像一个队列,用于存放数据,没有任何协调保证。如果多个例程同时从通道读取或写入数据,你不会因此而出现恐慌,但是如果你希望程序正常工作,你需要自己使用通道来协调这些例程。
英文:
I wouldn't say that's accurate. On the first point there aren't any compile time guarantees about dead locking, if you use a mutex poorly you will be dead locking, no compiler can prevent that. You can test for race conditions easily, but that's different.
On the second point, the channel serializes your asynchronous operations but I don't think how you state it makes much sense. A bunch of goroutines can be writing to and reading from it. It's just like a queue to put the data in, no coordination is guaranteed. You won't panic due to multiple routines reading off it or writing to it at the same time but if you have that happening Go isn't doing anything to make your program work well, you have to coordinate the routines yourself using channels.
答案2
得分: 2
不,第一个完全错误,第二个至少陈述不清楚或奇怪。
英文:
No, the first is completely wrong and the second is at least stated unclear or strange.
答案3
得分: -2
根据这个教程,它可以捕获一些死锁。虽然我还没有仔细阅读这个教程...
http://guzalexander.com/2013/12/06/golang-channels-tutorial.html
英文:
According to this tutorial, it can catch some deadlocks. I've not gone though this tutorial though...
http://guzalexander.com/2013/12/06/golang-channels-tutorial.html[enter link description here]1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论