V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
ponymaggie

unbuffered channel 和只有一个元素的 buffered channel 有啥区别

  •  
  •   ponymaggie · Jun 21, 2022 · 1631 views
    This topic created in 1418 days ago, the information mentioned may be changed or developed.

    比如:

    sema = make(chan struct{}, 1)

    和 sema = make(chan struct{})

    都是只能放一个元素,读取之前再放的话就会等待

    2 replies    2022-06-21 15:59:05 +08:00
    iBugOne
        1
    iBugOne  
       Jun 21, 2022   ❤️ 1
    unbuffered channel 第一个元素都放不进去吧,会卡到有人读才行

    https://go.dev/play/p/UJGaZDcKzDW
    qianxi0410
        2
    qianxi0410  
       Jun 21, 2022
    unbuffered channel 会卡发送者,buffer channel 不卡
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1360 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 17:23 · PVG 01:23 · LAX 10:23 · JFK 13:23
    ♥ Do have faith in what you're doing.