Coder Social home page Coder Social logo

Comments (2)

niyanchun avatar niyanchun commented on June 9, 2024

@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.

lycheng avatar lycheng commented on June 9, 2024

是的,这个我自己测试的时候发现了

谢谢

from the-golang-standard-library-by-example.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.