Comments (2)
@lycheng 我再Mac上面测试了一下这个程序,没有问题。但是在Ubuntu上面测会出现你说的这种问题,我debug了一下,看了一下调用栈:
(dlv) bt
0 0x0000000000453693 in runtime.futex
at /usr/local/go/src/runtime/sys_linux_amd64.s:388
1 0x00000000004238de in runtime.futexsleep
at /usr/local/go/src/runtime/os_linux.go:62
2 0x000000000040c370 in runtime.notetsleep_internal
at /usr/local/go/src/runtime/lock_futex.go:174
3 0x000000000040c4e2 in runtime.notetsleepg
at /usr/local/go/src/runtime/lock_futex.go:206
4 0x000000000043fff8 in runtime.timerproc
at /usr/local/go/src/runtime/time.go:209
5 0x00000000004525f0 in runtime.goexit
at /usr/local/go/src/runtime/asm_amd64.s:2086
(dlv) goroutine
Thread 9327 at /usr/local/go/src/runtime/sys_linux_amd64.s:388
Goroutine 15:
Runtime: /usr/local/go/src/runtime/lock_futex.go:206 runtime.notetsleepg (0x40c4e2)
User: /usr/local/go/src/runtime/lock_futex.go:206 runtime.notetsleepg (0x40c4e2)
Go: /usr/local/go/src/runtime/time.go:97 runtime.addtimerLocked (0x43fc2e)
(dlv) goroutines
[15 goroutines]
Goroutine 1 - User: /usr/local/go/src/runtime/time.go:59 time.Sleep (0x43fa55)
Goroutine 2 - User: /usr/local/go/src/runtime/proc.go:260 runtime.gopark (0x4283fa)
Goroutine 3 - User: /usr/local/go/src/runtime/proc.go:260 runtime.gopark (0x4283fa)
Goroutine 4 - User: /usr/local/go/src/runtime/proc.go:260 runtime.gopark (0x4283fa)
Goroutine 5 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 6 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 7 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 8 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 9 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 10 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 11 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 12 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 13 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
Goroutine 14 - User: /usr/local/go/src/runtime/sema.go:267 sync.runtime_notifyListWait (0x436341)
- Goroutine 15 - User: /usr/local/go/src/runtime/lock_futex.go:206 runtime.notetsleepg (0x40c4e2)
有的goroutine卡在没有收到广播信号,所以我想问题出在当main goroutine执行cond.Broadcast()
的时候,有的goroutine还没有执行到cond.Wait()
。然后我测了一下,如果在main goroutine执行cond.Broadcast()
前加上time.Sleep
,保证所有的(当然不能完全保证)goroutine都运行到cond.Wait()
,这样就不会出现上面的情况了。你可以试一下~
from the-golang-standard-library-by-example.
是的,这个我自己测试的时候发现了
谢谢
from the-golang-standard-library-by-example.
Related Issues (20)
- 15.2 unsafe.Sizeof(int)结果应该是8
- 2.1.6 字符串 JOIN 函数, 实现方法已经修改
- 有一个问题 HOT 1
- log 包
- 怎么没有net包啊
- 啥时候更新啊, 第七章之后好多没更新了
- chapter01/01.4.md 上引用了不存在的超链接
- ”关闭文件“ 文档内容与源文件内容不一致
- Sort should add SliceStable
- 发现一个小问题,不知是否是写错
- sort包有一章节无法点击跳转
- 第七章说连接池工作原理的时候重试次数不是2吗
- 图片挂了? HOT 3
- 问下作者,这个还更新吗?好多章节没有呢
- 补全了部分基础库的案例
- 3.1.1 数据集合排序
- 网络包 net
- 第一章IO 1.4. ReaderAt 和 WriterAt 接口中
- 第一章 1. 1.2 ioutil — 方便的IO操作函数集
- ioutil is deprecated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from the-golang-standard-library-by-example.