zoukankan      html  css  js  c++  java
  • How to Gracefully Close Channels

    小结:

    1、

    When a goroutine sends a value to a channel, we can view the goroutine releases the ownership of some values. When a goroutine receives a value from a channel, we can view the goroutine acquires the ownerships of some values.

    Surely, there may be also not any ownership transferred along with channel communications.

    The values (whose ownerships are transferred) are often referenced (but are not required to be referenced) by the transferred value. Please note, here, when we talk about ownership, we mean the ownership from the logic view. Unlike Rust language, Go doesn't ensure value ownership from the syntax level. Go channels can help programmers write data races free code easily, but Go channels can't prevent programmers from writing bad concurrent code from the syntax level.

    2、

    only channel is first-class citizen in Go. Channel is one kind of types in Go, so we can use channels without importing any packages. On the other hand, those traditional concurrency synchronization techniques are provided in the sync and sync/atomic standard packages.

    Honestly, each concurrency synchronization technique has its own best use scenarios. 

     3、

    One problem of channels is, the experience of programming with channels is so enjoyable and fun that programmers often even prefer to use channels for the scenarios which channels are not best for.

    Channels in Go - Go 101: an online Go programming book + knowledge base https://go101.org/article/channel.html

    How to Gracefully Close Channels - Go 101: an online Go programming book + knowledge base https://go101.org/article/channel-closing.html

     Channel Use Cases - Go 101: an online Go programming book + knowledge base https://go101.org/article/channel-use-cases.html

  • 相关阅读:
    每日二题20201117(34. 在排序数组中查找元素的第一个和最后一个位置)
    【CQOI2011】动态逆序对
    P3584 [POI2015]LAS
    P4643 [国家集训队]阿狸和桃子的游戏
    【CF555E】Case of Computer Network
    P3810 【模板】三维偏序(陌上花开)
    P3391 【模板】文艺平衡树(Splay)
    P3690 【模板】Link Cut Tree (动态树)
    【CF161D】Distance in Tree
    P3806 【模板】点分治1
  • 原文地址:https://www.cnblogs.com/rsapaper/p/12213238.html
Copyright © 2011-2022 走看看