• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
留白
世人慌慌张张,不过图碎银几两
博客园    首页    新随笔       管理    订阅  订阅
2020年7月20日
go tour --sync.Mutex 互斥锁
摘要: package main import ( "fmt" "sync" "time" ) // SafeCounter is safe to use concurrently. type SafeCounter struct { mu sync.Mutex v map[string]int } // 阅读全文
posted @ 2020-07-20 15:32 留白s 阅读(131) 评论(0) 推荐(0)
go tour --Exercise: Equivalent Binary Trees
摘要: package main import ( "golang.org/x/tour/tree" "fmt" ) // Walk walks the tree t sending all values // from the tree to the channel ch. func Walk(t *tr 阅读全文
posted @ 2020-07-20 15:23 留白s 阅读(280) 评论(0) 推荐(0)
go tour --select or Default Selection
摘要: select语句让goroutine等待多个通信操作。 select会一直阻塞,直到其中一个case可以运行,然后执行那个case。如果有多个就绪,它就随机选择一个。 package main import "fmt" func fibonacci(c, quit chan int) { x, y 阅读全文
posted @ 2020-07-20 14:40 留白s 阅读(151) 评论(0) 推荐(0)
go tour --Channels 与 Buffered Channels
摘要: 无缓冲通道(阻塞通道) 写入后立即阻塞,需要另一个协程读取通道的数据后,才能继续执行。 通道操作符 ch <- v // Send v to channel ch. v := <-ch // Receive from ch, and // assign value to v. 无缓冲通道 ch := 阅读全文
posted @ 2020-07-20 14:35 留白s 阅读(138) 评论(0) 推荐(0)
go tour --Exercise: Images
摘要: package main import ( "golang.org/x/tour/pic" "image/color" "image" ) type Image struct{} func (i Image) ColorModel() color.Model { return color.RGBAM 阅读全文
posted @ 2020-07-20 11:46 留白s 阅读(332) 评论(0) 推荐(0)
go tour --Exercise: rot13Reader
摘要: package main import ( "io" "os" "strings" ) type rot13Reader struct { r io.Reader } func (rot rot13Reader) Read (b []byte) (int, error){ n, error := r 阅读全文
posted @ 2020-07-20 11:14 留白s 阅读(221) 评论(0) 推荐(1)
go tour --Exercise: Readers
摘要: package main import "golang.org/x/tour/reader" type MyReader struct{} // TODO: Add a Read([]byte) (int, error) method to MyReader. func (m MyReader) R 阅读全文
posted @ 2020-07-20 10:17 留白s 阅读(352) 评论(0) 推荐(0)
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3